Professional Documents
Culture Documents
2 Let n = 4 and (a 1, a2, a3, a4) = (das, fish, ink, watch). Let p( 1: 4) = (4, 6, 8, 2)
and q(0:4) = (6, 6, 6, 6, 5). The p's and q's have been multiplied by 100 for
convenience. Use dynamic programming technique to find the optimal binary
search tree. Write all the values used at one stage to calculate the next stage and
so on. Show the values in table and construct the final optimal binary search tree 7
also.
3 Use dynamic programming to fully parenthesize the product of five matrices, i.e.
A [2 x 5], B [5 x 3], C [3 x 6], D [6 x 10], E [10 x 7] such that the number of
scalar multiplications gets minimized. Show each and every step.
4
a) Given a sorted array A of n distinct positive and negative integers,
propose an efficient algorithm to find an index such that 1 < i <n and A[i]
= i, provided such an index exists. If there are many such indices, then
the algorithm can return anyone of them. What is the time complexity of
the proposed algorithm?
b) What would be the order of the following loops (give reason for your answer):
(i) (ii) (iii)
for i = 1 to 2n step 3 for i = n to I i=n
for j = n to I step -3 { for j = 1 to i while(i > 0)
x=x*(i*j)/ 2 for k = I to j { for j = 1 to n / 2
x=x*i*j y = y + i /2
i = i *2 i = i /2
} }
4,3