Page 1 of 4
Page 1 of 4
Instructor’s Signature
Page 2 of 4
b) What is the smallest value of n such that an algorithm whose running time is 100∗ 𝑛2 runs faster than an
algorithm whose running time is 2𝑛 on the same machine? (2)
i. Prove that function (n lg n) does not hold as the upper bound. (2)
0 2 1 1 5 6 5 3 9 4
i. Create a tree using Array indices. Given the index i of a node, the indices of its parent, left child, and right
child can be computed. (1)
ii. Convert this tree to Max Heap using BUILD_MAX_HEAP procedure as discussed in class. (2)
iii. Apply HEAPSORT procedure on Max Heap built in part (ii) to perform sorting (2)
b) Consider the list of student registration numbers that needs to be mapped in a hash table using double hashing.
Generate 7 roll numbers by incrementing 1 in your roll number each time.
For Example; if your roll number is 0211565394, then next 7 numbers with increment of 1 would be 0211565395,
0211565396, 0211565397, 0211565398, 0211565399, 0211565400, 0211565401. Then add these 7 numbers in a
hash table.
ℎ1 (𝑘) = ⌊ 𝑚 (𝑘 𝐴 𝑚𝑜𝑑1)⌋
Choose values for m and A and give reason of your choice. You can use any second hash function (h2) of your
choice. Give each step clearly. (5)
Page 3 of 4
c) Consider a 0-1 knapsack problem where a thief robbing a store finds n items. The ith item is worth vi dollars and
weighs wi pounds, where both are integers. The thief wants to take as valuable a load as possible, but he can carry
at most W pounds in his knapsack, for some integer W. Which items should he take? Consider list of following
items and find optimal list of items using dynamic programming’s tabulation method. (5)
Item vi wi
A 23 5
W=8
B 21 3
C 14 4
D 19 6
E 12 5
F 10 2
d) Consider the following list of activities for ‘Activity Selection Problem’ in which the objective is to complete the
maximum number of activities that are compatible with each other.
i. Suppose that instead of always selecting the first activity to finish, we instead select the last activity to
start that is compatible with all previously selected activities. Describe how this approach is a greedy
algorithm and prove that it yields an optimal solution using following example. (2)
ii. Not just any greedy approach to the activity-selection problem produces a maximum-size set of mutually
compatible activities. Give an example to show that the approach of selecting the activity of least duration
from among those that are compatible with previously selected activities does not work. (3)
Note: Your content will be checked for plagiarism so avoid copying from internet and write in your own words.
Note:
Students are expected to consider the following rubrics for guidance while attempting this exam. Rubric is a set of criteria
for grading student’s effort and a scoring guide used to evaluate the quality of responses.
Excellent
understanding of basic Good understanding Good understanding Poor understanding of
Knowledge of
and advanced of basic and advanced of basic concepts of basic concepts of
Course
concepts of course concepts of course. course course
with applications.