0% found this document useful (0 votes)
9 views10 pages

CSI247

This document outlines the final examination for the Computer Science course CSI 247, focusing on Data Structures for the academic year 2023/24. It includes instructions for the exam format, sections for multiple choice, short answers, and programming questions, along with specific tasks related to Java programming and data structures. The total marks for the exam are 100, and it consists of 10 pages.

Uploaded by

plutoagcorp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

CSI247

This document outlines the final examination for the Computer Science course CSI 247, focusing on Data Structures for the academic year 2023/24. It includes instructions for the exam format, sections for multiple choice, short answers, and programming questions, along with specific tasks related to Java programming and data structures. The total marks for the exam are 100, and it consists of 10 pages.

Uploaded by

plutoagcorp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

FACULTY OF SCIENCES

DEPARTMENT OF COMPUTER SCIENCE


ACADEMIC YEAR 2023/24

Final Examination
Course Code: CSI 247 Subject: COMPUTER SCIENCE
Title of Paper: DATA STRUCTURES

Semester: 1
Time Allowed: 180 MINUTES Reading Time:10 MINUTES Maximum Marks: 100
Student’s Surname _______________________ Firstname ___________________________
Student’s ID _______________
Instructions:
a) No aids of any kind allowed.
b) Answer ALL questions.
c) For section A (multiple choice) write your answers in the front page.
d) Section B & C: Answers must be written in the provided space on the question and
use the back of the page for rough work.
e) READ QUESTIONS CAREFULLY and write legibly.
f) Do not include comments in your programs.

Section A: Multiple Choice

Question Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10
Mark: / 10
Answer
/10
Section B: Short Answers

Question Q1 Q2 Q3 Q4 Q5 Mark: /40


Mark /6 /4 /13 /8 /9

Section C: Programming
Question Q1 Q2 Mark: /50
Mark /40 /10
/45
Total: 100

DO NOT OPEN THIS PAGE UNTIL YOU HAVE BEEN TOLD TO DO SO


----------------------------------------------------------------------------------------------------------------
NUMBER OF PAGES INCLUDING THE COVER 10

Page 1 of 10
Section A: Multiple choice [10 marks]
1. When does a normal queue that is implemented using an array of size 10 get full?

A. When tail = 10
B. When tail = 9
C. When front = tail + 1
D. When tail = front

2. Which one is the correct declaration for implementing two interfaces?

A. class C implements A, B
B. class C implements A, implements B
C. class C implements A extends B
D. class C implements A & B

3. What will be the output of the following Java program?


class Recursion {
int function (int n){
int res;
res = function (n - 1);
return res;
}

public static void main(String[] args) {


Recursion ob = new Recursion() ;
System.out.print(ob.function(9));
}
}

A. 0
B. 1
C. Compilation Error
D. Runtime Error

4. What is the worst case Big-O notation of the following code segment?
for ( int i=0; i < n; i++)
System.out.println(i);
for ( int j = 0; j < n; j++)
for ( int k = 0; k < n ; k++)
System.out.println(k);

A. O(1)
B. O(n)
C. O(n2)
D. O(log n)

Page 2 of 10
5. What is the effect of implementing class A constructor private?

A. Any class can instantiate objects of class A


B. Objects of class A can be instantiated only within the class where it is
declared
C. Any inheriting class can instantiate objects of class A
D. Classes within the same package as class A can instantiate objects of

6. What is will be the output?


class Box {
int w;
int h;
int l;
// default constructor here
}

class Testing{
public static void main(String args[]) {
Box b1 = new Box();
Box b2 = new Box();
b1.h = 5;
b1.l = 2;
b1.w = 4;
b2.l = b2.h = 9;
b2 = b1;
System.out.println(b2.h);
}
}

A. 2
B. 4
C. 5
D. 9

7. What will be the output of the following Java code?


class A {
static int x;
void increment() {
x++;
}
}
class ATester {
public static void main(String args[]) {
A ob1 = new A();
A ob2 = new A();
obj.x = 0;
ob1.increment();
ob2.increment();
System.out.println(ob1.x + " " + ob2.x);
}
}
Page 3 of 10
A. 12
B. 11
C. 22
D. Compilation Error

8. Where are linked lists elements stored?

A. In an array
B. In a structure
C. In contiguous locations in memory
D. Anywhere in memory where the computer has space for them

9. Consider code below:

interface A {
void a();
}
abstract class B implements A {
abstract void b();
}
class C extends B {
//Missing methods
}
Which of these when added to class C will lead to successful compilation of the
above Java program?

A. @Override
public void a() { }
@Override
void b() {}

B. @Override
public void a() { }
@Override
Abstract void b() { }
C. @Override
public void a() { }

D. @Override
void b() { }

10. How will the unsorted array below look like at the end of the first pass when
sorting it using bubble sort?

7 2 9 6 4

A. 2 4 6 7 9
B. 2 7 6 4 9
C. 2 7 6 9 4
D. 2 7 4 6 9
Page 4 of 10
Section B

1. Write a recursive method called power that takes int variables a and b, and
returns ab. [6]

2. Suppose a Java defined ArrayList object called myList has been initialized
correctly and myList has some elements. Write Java code segment that creates an
Iterator on myList called itr and use it to sum elements in the list. Assume the
necessary import statements have been written. [4]

3. Write a static method called sortArray which accepts an array of integer values
and implements the selection sort algorithm in ascending order [13]

Page 5 of 10
4. Assuming an initially empty stack with capacity of 4, fill diagrams below with
correct details to show stack contents and variable top after executing each of the
following instructions. Give comments where the operation leads to a problem
[8]

a) push(17), push(34), push(28), push(47)

top

b) push(72)
top

c) pop()
top

d) peek()
top

5. Write a Java generic method frequency that takes a generic arrays of strictly
number types only and a target element. The method must return the number of
times the element appears in the array. [9]

Section C

1. Class PQueue: [40]


Create a class called PQueue which implements a queue ADT that stores patients’
names using singly linked list. The class should include an inner class called PNode
and the different methods to manipulate patient names in the queue. The class must
have the following instance variables: front and rear for tracking the beginning and
the end of the queue and n for the number of elements in the queue.
Page 6 of 10
Implement the following methods in PQueue:
a) Default Constructor which uses front, rear and n to create an empty queue.
b) size(): returns number of patients in the queue
c) isEmpty(): determines if there are any patients in the queue or not
d) enqueue(): add a given patient’s name to the queue
e) dequeue(): removes and returns a patient’s name
f) peek(): returns the patient name at the front of the queue
g) findPatient(): determines if a given patient’s name is in the queue
h) printPatients(): Display all patient names in the queue

Page 7 of 10
Page 8 of 10
Page 9 of 10
3. Class MyPatients : [10]
Create an application tester class called MyPatients that uses the PQueue class and its
methods to create and manipulate a queue of patient names (e.g Jacobs Thabo).
Testing PQueue:
Create a queue of patient names called clinic. Using the most appropriate methods
from PQueue class write code to achieve the following operations:
a) Read 3 patient names from keyboard and add them to the queue clinic.
b) Remove two patient names from the queue and display their names with
messages that they have been attended to.
c) Add the patient name Jacobs Thabo
d) Determine if patient name Amano Sebina is in the queue and display an
appropriate message based on the outcome.
e) Display total number of patient names currently in the queue, and their full
details.

Page 10 of 10

You might also like