CS214 Exam 2019
CS214 Exam 2019
SCIMS, FSTE
Final Examination
Semester II, 2019
F2F/Blended Mode
Total Marks: 40
Instructions:
ID:___________________________ Name:_____________________________
SeatNo: _______________________
ID: ______________________
8. For the given phrase “tuition at institution”, find its corresponding encoded value using
Huffman’s algorithm and calculate the ratio of compression achieved. (4 Marks)
Note: Each character in a phrase occupies 1 byte of memory and ignore the blanks in the given
phrase.
Page 9
ID: ______________________
9. (a) Write a pseudo code to disperse change from vending machine using greedy approach
(2 Marks)
(b) Apply Greedy approach to give a change of 78c from available coins 54c, 44c, 34c, 14c, 4c, 2c.
Justify whether you have got locally optimal or globally optimal solution. (1 Mark)
Page 10
ID: ______________________
10. (a) Find the minimum cost spanning tree for the given graph using prim’s and kruskal’s
algorithm. Show the output after every stage while using these algorithms (4 Marks)
Page 11
ID: ______________________
(b) Which is the better of two algorithms for the above graph? Explain your answer. (1 Mark)
11. Use the single source shortest path algorithm to obtain in nondecreasing order the lengths of
the shortest paths from vertex 1 to all the remaining vertices in the digraph given below.
(2 Marks)
Page 12
ID: ______________________
12. Consider the 0-1 Knapsack problem with four different items having different weights and
profit values:
Item 1 (2 kg, $3)
Item 2 (3kg, $5)
Item 3 (4kg, $6)
Item 4 (5kg, $10)
The knapsack has a capacity of 8kg
(a) Use the greedy approach to compute the optimal profit in filling the knapsack ( 1 Mark)
(b) Use the backtracking algorithm for the above 0-1 knapsack problem to maximize the profit and
show the state space tree (4 Marks)
Page 13
ID: ______________________
(c) Which is the better of two approaches above? Explain your answer. (1 Mark)
Page 14