0% found this document useful (0 votes)
24 views

CNS 2102 - Data Structures and Algorithms - July 2022

Past paper questions for the year 2022

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)
24 views

CNS 2102 - Data Structures and Algorithms - July 2022

Past paper questions for the year 2022

Uploaded by

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

SCHOOL OF COMPUTING AND ENGENEERING SCIENCES

BACHELOR OF SCIENCE IN COMPUTER NETWORKS AND CYBER SECURITY


CNS 2102: DATA STRUCTURES AND ALGORITHMS
END OF SEMESTER EXAMINATION

DATE: 29th July2022 Time: 2 Hours


INSTRUCTIONS
1. Answer Question 1 (Compulsory) and any other Two Questions.
2. In the calculations, show your workings for full marks.

QUESTION 1: - COMPULSORY 30 Marks

a. For each functions f(n) below, give an asymptotic upper bound using “big-Oh” notation. (6
Marks)
i. f(n) = 100n3 − 7n 3 + 14n2
ii. f(n) = 100 − 100n3 + 7n2
iii. f(n) = log (7n 2)
iv. f(n) = .001n + 100 ꞏ 2 n
v. f(n) = n3 (1 + 6n + 2014n2)
vi. f(n) = (log n) x (n + n2)
b. Evaluate the following. (ab*cd/+) where a=3, b=5, c=8, d=2. (4 Marks)
c. Explain Data abstraction? (2 Marks)
d. A loop invariant is some predicate (condition) that holds for every iteration in the loop.
Discuss the three properties of a loop invariant. (3 Marks)
e. Distinguish between iterative algorithms and recursive algorithms with regards to Execution
Approach, Time Efficiency and Usage. (2 Marks)
f. Depth first traversal (DFT) can be used to perform various tasks including network analysis.
In full detail, describe the DFT algorithm. (4 Marks)
g. Describe any three differences between Arrays and Vectors (3 Marks).
h. Complete the bellow Java code by writing a method that can be used to add a new node with
a string data type at the head position of a linked-list. Ensure you name the method ‘element
_insert’ (4 Marks)

public class Linked_Lists {


Node head;
class Node {
Node next; int data;
public Node(int data) {this.data = data;} // Node constructor
}
public void element_insert(string data) {
.... . . . . . . . .
}}

i. Explain recursive how one can write recursive functions (2 Marks)

QUESTION 2 15 Marks

a. An algorithm can be classified as either totally or partially correct. Explain the difference
between these two classifications. (2 Marks)
b. Use the Principle of Mathematical Induction to verify that, the nth Odd number is given by,
2𝑛 1 . (6 Marks)

c. State the formal Big O definition and show that: 4x3 + 12 is O(x3) (4 Marks)
d. Consider the table below with variable k and pointer i
Name Value Memory Address
i (pointer) 000RT4 0000RQ
k 200 000RT4

Given the following sequence of commands, find the final value of integer variable k. Show
your working. (3 Marks)

*i = *i + 100

*i = k - 150

k = *i / 50 + k
QUESTION 3 15 Marks

a. Fill in the table below using the relevant Space Complexity notations for each of the listed
algorithms (3 Marks).

Algorithm Space Complexity


Insertion Sort
Merge Sort
Bubble Sort

b. The Java code snippet bellow shows how the core logic of a Bubble sort algorithm can be
implemented to achieve a complexity of O(n2). Discuss the drawbacks of this approach and
suggest one way of improving the implementation. (3 Marks)

c. Explain why Selection Sort and Insertion Sort algorithms are considered improvements of
Bubble Sort? (2 Marks)
d. Using relevant example, discuss the difference between an In-Place and Out-of-Place
algorithm? (4 Marks)
e. In a step-by-step order, list the steps involved in a Quick Sort algorithm. (3 Marks)
QUESTION 4 15 Marks
a. Describe any two applications of Breadth First Search. (2 Marks)
b. Explain the conditions for implementing Dijkstra’s algorithm? (2 Marks)
c. Consider the non-linear structure below.

7 6
Source P Q R

3
2 1 6

S T
2

i. Apply Dijkstra’s algorithm to find the shortest distances from the source to each node
in the table below. (5 Marks)

Vertex Shortest Distance from Source


P
Q
R
S
T

ii. State the shortest path to get to node R, assuming node R acts as a destination. (1 Mark)
d. Create an adjacency matrix to represent the undirected-weighted graph given below. (5 Marks)
QUESTION 5 15 Marks

a. Describe an AVL tree? (2 Marks)


b. Create a BST for the number sequence. 94, 72, 110, 87, 42, 21, 51, 84, 121, 100, 106 (3 Marks)
c. From the BST created in question b, add two nodes with the values 103 and 88. Balance the
resulting BST tree to form an AVL tree. (3 Marks)
d. Tree Traversal is a process used to visit all the nodes of a tree while using recursion. Discuss
the steps involved in all three approaches used for tree traversals. (3 Marks)
e. An inset operation is one of the many operations that can be performed on a Binary Search
Tree. In a step-by-step format, write down an algorithm that can be used to perform an
element insertion in a BST. (4 Marks).

You might also like