Dsad
Dsad
Note:
1. Please follow all the Instructions to Candidates given on the cover page of the answer book.
2. All parts of a question should be answered consecutively. Each answer should start from a fresh page.
3. Assumptions made if any, should be stated clearly at the beginning of your answer.
1𝑛 =0
1. Find the recurrence relation of T(n) = ! [3M]
𝑇(𝑛 − 1) + log 𝑛 , 𝑛 > 0
3. Fill out the bottom-up dynamic programming table for the 0-1 knapsack program. given
a 10 kg sack and the following items [4M]
I 1 2 3 4
Vi 10 40 30 50
Wi 5 4 6 3
5. Use Kruskal’s algorithm, to find a minimum spanning tree of the given graph below.
Draw the resulting spanning tree and list the edge in the order they are picked by the
Kruskal’s algorithm. [4M]
Fig-1
Page 1 of 2
6. Get the transitive closure of the relation represented by the digraph below. Use the
warshall’s algorithm. All steps needed, and draw the digraph of the transitive closure
[4M]
7. Finding the median of a sorted array is easy: return the middle element. But what if you
are given two sorted arrays A and B. of size m and n respectively, and you want to find
the median of all the numbers in A and B? you may assume that A and B are disjoint .
a. Give a naïve algorithm running is 𝜃(m+n) time. [2M]
b. If m =n, give an algorithm that runs in 𝜃(logn)time. [2M]
8. The input for this problem is a set of n-tasks a1…an the tasks are to be executed by a
single processor starting at time t=0.each task ai requires one unit of processing time
and has an integer deadline di. moreover, if the processor finishes executing ai at time
t, where di ≤ t, then a profit pi is earned. Apply a greedy algorithm for maximizing the
total profit. [hint: if two tasks have the same profit, then ties are broken by alphabetical
order] [4M]
Task A B C D E F G H I J K
Deadline 4 3 1 4 3 1 4 6 8 2 7
Profit 40 50 20 30 50 30 40 10 60 20 50
9. Construct a KD tree for the following data. (5,8,7,9),( 4,3,2,1), (6,8,3,4), (8,9,6,2),
(7,7,6,3), (8,7,8,4), (9,6,9,2), (10,5,7,1). [3M]
10. Suppose that we use a linked list to represent a queue and that in addition to the enqueue
and dequeue functions(i.e., functions to add and remove elements from the linked list),
you want to add a new operation to the queue that deletes the last element of the queue.
Which linked structure do we need to use to guarantee that this operation is also
executed in constant time? Justify your answer. [3M]
Page 2 of 2