Roll Number:__________________________
Thapar University, Patiala
Computer Science & Engineering Department
END SEMESTER EXAMINATION
B. E. (3 Year): Semester-5 (2020-21)
rd Course Code: UCS415
Course Name: Design & Analysis of Algorithms
January 29, 2021 Monday, 14.30PM
Time: 2 Hours, M. Marks: 50 Name Of Faculty: Rajiv Kumar, Rajesh
Mehta, Ashish Giridhar
1 Let n = 4 and (𝑎1 , 𝑎2 , 𝑎3 , 𝑎4 ) = (das, fish, ink, watch). Let p( 1: 4) = (4, 6, 8, 2)
and q(0:4) = (6, 6, 6, 6, 5). The p's and q's have been multiplied by 100 for
convenience. Use dynamic programming technique to find the optimal binary
search tree. Write all the values used at one stage to calculate the next stage and
so on. Show the values in table and construct the final optimal binary search tree 10
also.
2 a) Solve the following recurrence relation using recursive tree method.
n n 2
T ( ) T n n 1
T ( n) 4 2
n 1
1
b) Explain the backtracking algorithm to find the Hamiltonian cycle of a
graph G. Find the Hamiltonian cycle of the graph shown in following 5,5
below:
3 Consider the following matrix showing the distance between different
cities. Solve the Travelling salesman problem and draw the complete state
space tree using branch and bound algorithm. Also find the optimal
solution starting from city 0.
10
4 Explain the maximum flow problem and apply Ford Fulkerson algorithm to find
the maximum flow of the network shown below from source S to destination T.
(show each step of algorithm). Also explain: (a) Augmented path (b) Residual
graph (c) Minimal cut (d) Residual capacity.
1,5,4
5 What is a min cut of a graph G? Write the Karger’s min cut algorithm and
apply the same on the graph given below (show intermediate steps)
2,3,5
6 Working modulo q = 11, how many spurious hits does the Rabin-Karp matcher 10
encounter in the text T =
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
When looking for the pattern P = 26? Explain your answer with proper
implementation of Rabin-Karp algorithm.
7 (a) By explaining the difference between deterministic and non-deterministic
algorithm with example. Also write a short note on P, NP, NP hard and NP 5,5
complete class problems.
(b) If possible, find the topological sort for the graph G having 6 vertices. (for
an ordered pair (x, y) means there is an edge from x to y)
G= { (a, b), (a, c), (b ,d), (b, e), (d, e), (d, f), (a, e)}