You are on page 1of 6

Sri Lanka Institute of Information Technology

B.Sc. Honours Degree in Information Technology


Specialized in Cyber Security

Supplementary Examination
Year 2, Semester 2 (2022)

IE2072 – Foundations of Algorithms

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

Question 2 (30 marks)


(a) Briefly define the concept of String Matching. (2 marks)
(b) Draw the state chart machine for P = aaba for the input alphabet = {a,b}. (10 marks)
(c) How many total comparisons would occur for searching the pattern ‘aab’ through the text
‘aaabbbcaab’. (3 marks)
(d) Using the Text in (c), demonstrate a methodology to minimize the number of comparisons.
Note: You may assume the pattern and do the demonstration. (3 marks)
(e) Construct the Shanon Fano codeward for the following frequencies. (8 marks)

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)

Question 4 (25 marks)


(a) Define the term Optimal Solution. (2 marks)
(b) State one difference between the usage of Kruskal’s algorithm and Dijkstra’s algorithm.
(2 marks)
(c) Illustrate the steps to obtain the MCST for the following graph using Kruksal’s algorithm.
For the illustration purpose, assign values only once to the given algorithm and then use
diagrammatic approach to reach the final answer. Hence, find the minimum cost of the
given graph. (12 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

END OF THE PAPER

Page 6 of 6

You might also like