You are on page 1of 1

Roll No.

Thapar Institute of Engineering and Technology, Patiala


Computer Science & Engineering Department
B. E. (3rd Year) CSBS: Semester-5 (2022-23) Course Code: UCT501
Course Name: Design & Analysis of Algorithms
September 24, 2022 Saturday, 01.00PM
Time: 2 Hours, M. Marks: 25 Name of Faculty: Dr. Rajiv Kumar
Note : Attempt ALL questions. All parts of a Question should be done at one place. Assume any
logical data with reasoning, if missing.

Five athletes (say) A, B, C, D, and E are practicing on a single lane track of


2500 meters. Athlete A starts immediately and completes in 14 minutes. Athletes
B and C start after 15 minutes taking 22 and 23 minutes respectively, to
complete. D starts 2 minutes after the B athlete completes, and finishes in 15
minutes. Athlete E starts 40 minutes late and completes in 17 minutes.
Determine all the possible schedules that allow the maximum number of athletes
5
to practice?

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

You might also like