Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
32 views

CNS 2101 - Data Structures and Algorithms - July 2023

Past Paper questions

Uploaded by

lisa.sayi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

CNS 2101 - Data Structures and Algorithms - July 2023

Past Paper questions

Uploaded by

lisa.sayi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SCHOOL OF COMPUTING AND ENGINEERING SCIENCES

BSC INFORMATICS AND COMPUTER SCIENCE


BSC COMPUTER NETWORKS AND SECURITY
END OF SEMESTER EXAMINATION
ICS 1201: DATA STRUCTURES AND ALGORITHMS
CNS 2101: DATA STRUCTURES AND ALGORITHMS

DATE:27th July 2022 Time: 2 Hours

Instructions
1. This examination consists of FIVE questions.
2. Answer Question ONE (COMPULSORY) and any other TWO questions.

Question 1
a) Explain the difference between a data structure and an abstract data type.

(3 marks)
b) Explain the meaning of asymptotic analysis of an algorithm.

(3 marks)
c) Explain the design considerations for recursive algorithms.

(3 marks)
d) Write an algorithm/pseudocode for selection sort. Illustrate the working of the algorithm
using the following array of five numbers:

6, 3, 9, 1, 7

(5 marks)
e) Construct a binary tree for the arithmetic expression ((a + b) ∗ c) - d and then perform a
post-order traversal.

(4 marks)
f) State two applications of the following:
i. Stack
ii. Trees
iii. Graph

(6 marks)

Page 1 of 4
g) Analyse the Big-Oh running time of the following:
i. Code snippet 2A

(3 marks)
ii. Algorithm 2B
// Sum of an array of sequential numbers
const array = [1,2,3,4,5,6,7,8];

function determineSumOfSequentialArray(array) {
return array.length * (array.length + 1)/2;
}

(3 marks)

Question 2

a) Explain two applications of queues.

(3 marks)
b) Convert the following infix notation to both prefix and postfix notation:

((A+B) * C – (D-E) ^ (F+G))

(4 marks)
c) Assuming an array implementation of a stack, write algorithms for the following stack
operations:
i. Pop
ii. If stack is full

(4 marks)
d) Assuming circular array implementation of a queue, write algorithms for the following
queue operations:
i. Insert / Enqueue
ii. Remove / Dequeue

(4 marks)

Question 3
a) Explain two differences between an array and a linked list.

(3 marks)
b) Explain two applications of a linked list.

Page 2 of 4
(3 marks)
c) Write a pseudocode for the following linked list operations:
i. Adding a node to the head of a linked list.
ii. Finding specific key value in a linked list.
iii. Deleting a node.

(9 marks)

Question 4
a) Write an algorithm that uses recursion to find the power of a number e.g 24. Illustrate the
working of the algorithm by showing the series method calls and their return values for 24

(3 marks)
b) Distinguish between recursion and iteration.

(3 marks)
c) Suppose the following list of numbers is inserted in the order into an empty binary search
tree: 45, 33, 90, 33, 68, 72, 15, 24, 30, 66, 11, 50, 10.
i. Derive the binary search tree.
ii. Perform pre-order traversal on the derived binary search tree.

(4 marks)
d) Write Java method for inserting a node in a binary search tree.

(3 marks)
e) Write an algorithm or Java method for searching a key value in a binary search tree.

(2 marks)

Question 5
a) Perform the following traversals on the graph in Fig. Q5a
i. Depth first traversal. Show stack contents for each step
ii. Breadth first traversal. Show queue contents for each step.

Figure Q5a: Graph

(5 marks)

Page 3 of 4
b) Write an algorithm for merge sort. Illustrate the working of the algorithm using the
following array of five numbers: 6, 3, 9, 1, 7

(3 marks)
c) Using illustrations, explain the meaning of the following graph terms:
a. Degree of vertex
b. Cyclic graph

(3 marks)
d) Write an algorithm for binary search and illustrate the working of the algorithm using the
following numbers: 3,4,5,6,7,8,9.

(4 marks)

Page 4 of 4

You might also like