POKHARA UNIVERSIT Y
Level: Bachelor Semester: Spring Year : 2024
Programme: BE Full Marks: 100
Course: Data Structure and Algorithms (New) Pass Marks: 45
Time : 3 hrs.
Candidates are required to give their answers in their own words as far
as practicable.
The figures in the margin indicate full marks.
Attempt all the questions.
1. a) What is algorithm analysis? For the given algorithm, compute its 7
total running time T(n) for worst and best case.
Algorithm for XYZ (n) Cost Time
m=1 C1 1
for i=1 to n C2 n
for j=1 to n C3 n
xyz=i*j C4 n
return xyz C5 1
OR
What is a greedy algorithm? Explain how the greedy algorithm works
with an example of any greedy algorithm like Kruskal's algorithm.
b) How does a stack become an ADT? Implement stack using an array 8
with its basic operations.
2. a) What is a base case? Write a program in C or C++ to implement the 8
sum of n natural numbers using recursion and explain how the base
case is set and how it is reached.
b) Define Deque. State and explain in which scenario the Deque is used 7
in real world.
3. a) Define a node class for a singly linked list to contain a data and a link 8
to the next node. Implement the insertion operation to insert a node at
the end and display all the node data in the single linked list.
b) What is the advantage of linked implementation? Explain the linked 7
implementation of queue in detail.
4. a) Define Binary Search Tree. Construct a BST from the data: 7
43,60,30,20,18,54,58,12,32 and perform the following operations:
i. Traverse in preorder, in-order and post-order.
ii. Delete 30.
Page 1 of 2
b) Explain the problems with unbalanced binary trees. Create an AVL 8
tree from the following data: 17, 42, 9, 55, 23, 8, 36, 71, 65, 1, 7.
5. a) Perform heap sort on: 25,33,20,10,100,2,5, 40. 5
b) Design and implement a simple hash system with a hash function 10
where h(x)= x%10 using C or C++ code. If collision occurs, use
quadratic probing for collision resolution.
6. a) Define a directed graph. For the given graph, represent it using 7
adjacency matrix and find its transitive closure using Warshall's
algorithm.
b) Find the minimum spanning tree of the given graph using Prim’s 8
algorithm.
OR
Find the shortest path from the source vertex A to all vertices of the
following graph using Dijkstra’s algorithm.
7. Write short notes on: (Any two) 2×5
a) Types of data structure
b) Quick Sort Algorithm
c) Binary Search
Page 2 of 2