Set D Answer Key
Set D Answer Key
School of Computing
SET D
Course Code & Title: 21CSC204J & Design and Analysis of Algorithms Duration: 1 hour 40 minutes
1) (c) 5
2) (b) T has n/2 edges
3) (c) 5
4) (b) 2
5) (a) O(N!)
6) (c) Both BFS and DFS
7) (a) 12
8) (c) 3
PART B: Answer all questions. 3*5 = 15 marks
9) Imagine you are a puzzle enthusiast who loves solving word puzzles. You have two sets of
word tiles X and Y , each containing a sequence of letters arranged in a particular order, say
X = ACB#BAB and Y = BCCACAB, here # is an unknown character which can be A or B or C.
Your task is to find the value of # so that the length of the longest common subsequence is
3. Justify your choice of #.
The LCS for the above is 4. So there is no choice of # that will give the LCS as 3.
10) There is a maze to be travelled by a mouse to find its cheese. The mouse decide to follow an
arbitary path as far as it can go. If the mouse hits on a dead end (where it cannot move further),
then the mouse will take a detour and follow another path and keep repeating this until it finds its
cheese. If the junctions on the maze are represented as nodes and the various roads emerging from
the junction are represented as edges, then what kind of graph traversal would match the mouse’s
strategy to find the cheese. Apply your claimed traversal on the following graph representation of a
maze to help the mouse (at node 1) search for its cheese
The mouse's behavior is:
Follow a path as far as possible.
If it hits a dead end, backtrack and try a new path.
This matches exactly the strategy of Depth First Search (DFS) traversal. (1 Mark)
Now, applying DFS starting from node 1 on the given graph:
11.Given:
Pattern P=132P = 132P=132
Text T=335013265342T = 335013265342T=335013265342
Hash function:
h(S)=(sum of digits of S)mod
Process all substrings of length 3
T=335013265342
Substrings of length 3:
1. 335 → (3+3+5)=11 → 11 mod 5 = 1
2. 350 → (3+5+0)=8 → 8 mod 5 = 3
3. 501 → (5+0+1)=6 → 6 mod 5 = 1
4. 013 → (0+1+3)=4 → 4 mod 5 = 4
5. 132 → (1+3+2)=6 → 6 mod 5 = 1
6. 326 → (3+2+6)=11 → 11 mod 5 = 1
7. 265 → (2+6+5)=13 → 13 mod 5 = 3
8. 653 → (6+5+3)=14 → 14 mod 5 = 4
9. 534 → (5+3+4)=12 → 12 mod 5 = 2
10. 342 → (3+4+2)=9 → 9 mod 5 = 4
(OR)
12
i.
ii. 1.Create a leaf node for each unique character and build a min heap of all leaf nodes
2.Extract two nodes with the minimum frequency from the min heap.
3.Create a new internal node with a frequency equal to the sum of the two nodes
frequencies. Make the first extracted node as its left child and the other extracted
node as its right child. Add this node to the min heap.
4.Repeat steps#2 and #3 until the heap contains only one node. The remaining
node is the root node and the tree is complete.
iii.
iv.
13
(OR)
Solution:
14 .a)
(a) Define minimum vertex cover of a graph. (2 marks)
(b) Provide a polynomial-time approximation algorithm A to find a vertex cover (VC) of a graph. (3
marks)
(c) Using the above claimed algorithm A, find a vertex cover (say S) of the following graph starting
from the edge (M, R). (2 marks)
(d) Is the above vertex cover S a minimum vertex cover? If not, provide a minimum vertex cover of
the graph. (2 marks)
Solution:
a) A minimum vertex cover in a graph is a set of vertices that includes at least one endpoint of every
edge in the graph, and the set has the smallest possible size. In other words, it's the smallest group
of vertices that "covers" all the edges.
b)
c) S= {M,R,N,Q,O,P}
d) S is not minimum vertex Cover.
Minimum vertex cover Vc={M,N,O}
(OR)
Solution
i)
Statement A: True
Statement B: Unknown
Statement C: True
Statement D: False
ii)