Final - Exam - 2018 - PHD
Final - Exam - 2018 - PHD
Q4 [20 marks]
I. Suppose you are choosing between the following three algorithms: [15 marks]
1. Algorithm A solves problems by dividing them into five sub problems of half the size,
recursively solving each sub problem, and then combining the solutions in linear time.
2. Algorithm B solves problems of size n by recursively solving two sub problems of size
n − 1 and then combining the solutions in constant time.
3. Algorithm C solves problems of size n by dividing them into nine sub problems of size
n/3, recursively solving each sub problem, and then combining the solutions in O(n 2 )
time.
What are the running times of each of these algorithms (in big-O notation), and which would you
choose?
II. 3-way-Merge Sort: Suppose that instead of dividing in half at each step of Merge Sort,
you divide into thirds, sort each third, and finally combine all of them using a three-way
merge subroutine. What is the overall asymptotic running time of this algorithm? (Hint:
Note that the merge step can still be implemented in O(n) time.)
[5 marks]
Q5 [15marks] Get MST using prim and Kruskal [7.5 for each one]
start
12 8
2 9 1 9
5 3 11
8 7 3 5
1 10
Q6 [10 marks] Get shortest paths from node S to each node using Dijkstra algorithm
, show each step and show the color of each node and its BH.
Q8 [10 marks] Construct variable length code using Huffman for the following characters statistics A =
20 , B =30 , C = 15 , D=5, E=8, and F=22 .
Q9 [10 marks] several coins are placed in cells of an n × m board. A robot, located in the upper left cell
of the board, needs to collect as many of the coins as possible and bring them to the bottom
right cell. On each step, the robot can move either one cell to the right or one cell down from its
current location. Design A DP Algorithm to solve this problem, and what is its space and time
complexity and use the following counter example to apply your algorithm and what is the
maximum number of coins that robot can collect it
1 2 3 4 5 6