CS2005
CS2005
1[a] Define a data structure and explain the difference between linear and non-
linear data structures.
1[b] What are the primary operations performed on a stack? Provide a brief
explanation of each.
1[c] Describe a binary search tree (BST) and explain the properties that distinguish
it from a general binary tree.
1[d] What is a graph? Describe the difference between a directed graph and an
undirected graph.
[2.5×4]
2[a] Write an algorithm to sort and linear array using Quick Sort. Given the
following array: [34, 7, 23, 32, 5, 62], demonstrate the process of sorting it using
the Quick Sort algorithm. Show each step clearly.
2[b] Write an algorithm to reverse a linked list. Explain each step of your algorithm.
[5+5]
3[a] What is a priority queue, and how does it differ from a regular queue? Provide
an example of a situation where a priority queue would be useful.
3[b] Construct a binary search tree (BST) by inserting the following sequence of
numbers: 30, 10, 20, 50, 40, 70. Show the BST after each insertion.
[5+5]
4[a] Describe what a balanced tree is and explain the importance of balancing a
tree. (5 marks)
4[b] Design an algorithm to convert the following infix expression to a postfix
expression using the stack data structure: (A + B) * (C - D) / (E + F). Show each
step of the conversion process.
[5+5]
5[a] Write an algorithm to merge two sorted linked lists into one sorted linked list.
Explain the logic behind your algorithm.
5[b] Explain the differences between depth-first search (DFS) and breadth-first
search (BFS) in graph traversal. Discuss the advantages and disadvantages of
each method with examples of where each would be most effective.
[5+5]
Page 1 of 2
6[a] Sketch the binary search tree and AVL resulting from the insertion of the
following integer keys:
50, 72, 96, 94, 107, 26, 12, 11, 9, 2, 10, 25, 51, 21
Traverse both the tree in POST ORDER and PRE-ORDER
Covert the sketched tree into threaded binary tree.
Write your observations for the above process.
6[b] Explain the process of Heap sort. Write an algorithm to construct a min heap?
Construct max-heap from the following list. Sketch the heap after deleting 86?
What is the time complexity of the whole process?
{21, 6, 56, 61, 44, 7, 9, 86, 75, 32, 34, 4, 49}
[5+5]
7[a] Define ADT of a Binary search tree? Write a general algorithm to delete a node
from Binary tree.
7[b] A rooted tree with 12 nodes has its numbered 1 to 12 in preorder. When the tree
is traversed in post-order, the nodes are visited in the order.
3, 5, 4, 2, 7, 8, 6, 10, 11, 12, 9, 1
reconstruct the original tree form this information and show the tree
diagrammatically.
[5+5]
--------------------------------------- Good luck ---------------------------------------
Page 2 of 2