CT2 - D - Answer Key
CT2 - D - Answer Key
Q. Part A
No
1 The best-case and worst-case complexities of Binary Search are
a) O(1) and O(log n)
b) O(1) and O(n)
c) O(log n) and O(log n)
d) Both best and worst case is O(log n)
2 Algorithm A1 can compute min-max in a1 comparison without divide and conquer. Algorithm
A2 can compute min-max in a2 comparison with divide and conquer. What could be the
relation between al and a2 considering the worst-case scenarios?
a) a1 < a2
b) a1 > a2
c) a1 = a2
d) Depends on the input
3 Time complexity of Strassen’s matrix multiplication problem is:
a)
b)
c)
d)
4 Find the Euclidean distance between the po
ints (4,3) and (7,5)
a) √3
b) √13
c) √19
d) √5
5 Which algorithm strategy builds up a solution by choosing the option that looks the best at
every step.
a) greedy method
b) branch and bound
c) dynamic programming
d) divide and conquer
6 The total running time of fractional Knapsack problem using simple approach.
a) O(n)
b) O(log n)
c) O(2n log n)
d) O(2n)
7 Suppose the letters a, b, c, d, e has the probabilities 0.3, 0.3, 0.2, 0.1, 0.1, which of the
following is the Huffman code for the above letters?
a) 100, 110, 00, 10, 01
b) 10, 11, 00, 010, 011
c) 100, 110, 11, 10, 11
d) 10, 111, 00, 01, 01
8 Dynamic programming is characterized by
(1) Distinct sub-problems
(2) Overlapping sub-problems
(3) Optimal substructures
(4) Sub-optimal or near optimal substructures
a) 1 and 3
b) 2 and 3
c) 1 and 4
d) 2 and 4
9 Time complexity of Longest common subsequence using dynamic programming is
a) O(m!)
b) O(mn)
c) O(n!)
d) O(n)
10 Let X = ABRACADABRAAB and Y = YABBADABBADOO. The Longest Common Subsequence, Z,
of X and Y is
a) Z = DAB
b) Z = AAB
c) Z = ABADABA
d) Z = ABADABAAB
Part B
11 What is Master theorem to solve recurrence relations and solve the below relations using
master method.
a) 𝑇(𝑛) = 2𝑇 (𝑛) + √𝑛
4
b) 𝑇(𝑛) = 7𝑇 (𝑛) + 𝑛2
2
Solution:
a)
b)
12 Develop a straightforward and recursive algorithm using divide and conquer to find a
maximum and minimum number in a set of n elements. Explain with an example.
Solution:
Straightforward Method:
Compared to Naïve method, in divide and conquer approach, the number of comparisons is
less.
Examples to be given.
13 Determine the minimum cost spanning tree using Kruskal’s method.
Solution:
Cost = 37
14 Explain 0/1 Knapsack problem. Solve the following problem using Dynamic programming.
Max weight = 7, (P1, P2, P3, P4) = (1, 4, 5, 7) and (W1, W2, W3, W4) = (1, 3, 4, 5).
Solution:
Solution:
Example computations of C[1,2], C[1,3], C[1,4] to be given.
E.g.: