Professional Documents
Culture Documents
IE2072 Supplementary Paper
IE2072 Supplementary Paper
Supplementary Examination
Year 2, Semester 2 (2022)
Duration: 2 Hours
August 2022
Instructions to Candidates:
This paper has 4 questions.
Answer all questions in the booklet given.
The total marks for the paper is 100.
This paper contains 6 pages, including the cover page.
Electronic devices capable of storing and retrieving text, including
calculators and mobile phones are not allowed.
Question 1 (25 marks)
(a) Find the step count of the following pseudocodes using RAM Model (10 marks)
(i) (ii)
(b) Briefly describe the similarity between Quick Sort and Merge Sort algorithms (2 marks)
(c) Illustrate the steps of partition(A, p, r) applied for the given array A. For the illustration
purpose, assign values only once to the given algorithm and then use diagrammatic
approach to reach the final answer. (10 marks)
Page 2 of 6
(d) State the running time complexity of the following recurrence equation using Master
Theorem. (3 marks)
T(n) = 4T(n/2) + n3
Symbol a b c d e f
Frequency 1 3 4 6 5 7
(i) Hence, how many bits required to represent these symbols using Shanon Fano coding?
(2 marks)
(ii) How many bits required to represent these symbols using Unicode coding? (2 marks)
Page 3 of 6
Question 3 (20 marks)
(a) State any advantage of using Dynamic Programming. (2 marks)
(b) You have been given 4 metrics namely A1, A2, A3 and A4 with the orders of <2,3,5,4,6>
respectively. Find the optimal umber of scalar multiplications and their parenthethization
needed to multiply these 4 metrics using Dynamic Programming. (8 marks)
(c) Consider a bag pack with 5kg. You have been given 4 items with their weights 2kg, 3 kg,
4kg, 5kg and profits 4,8, 2, 10 respectively. Use 0/1 Knapsack problem to analyze the items
to be inputted to obtain the maximum profit. (10 marks)
Page 4 of 6
MST-KRUKSKAL(G, w)
1A←Ø
2 for each vertex v V[G]
3 do MAKE-SET (v)
4 sort the edges of E into non decreasing order by weight w
5 for each edge (u, v) E, taken in non decreasing order by weight
6 do if FIND-SET (u) ≠ FIND-SET (v)
7 then A ← A U {(u, v)}
8 UNION(u, v)
9 return A
(d) Illustrate the steps to obtain the shortest path for the following graph using Dijkstra’s
algorithm. For the illustration purpose, assign values only once to the given algorithm and
then use diagrammatic approach to reach the final answer. Consider the starting vertex as
1. (9 marks)
Page 5 of 6
INITIALIZE-SINGLE-SOURCE(G, s)
1 for each vertex v V[G]
2 do d[v] ← ∞
3 π[v] ← NIL
4 d[s] ← 0
DIJKSTRA(G, w, s)
1 INITIALIZE-SINGLE-SOURCE(G, s)
2 S←Ø
3 Q ← V[G]
4 while Q ≠ Ø
5 do u ← EXTRACT-MIN(Q)
6 S ← S {u}
7 for each vertex v Adj[u]
8 do RELAX(u, v, w)
RELAX(u, v, w)
1 if d[v] > d[u] + w(u, v)
2 then d[v] ← d[u] + w(u, v)
3 π[v] ← u
Page 6 of 6