2017 Est
2017 Est
2017 Est
Q.1 Consider a hash table consisting of M = 11 slots, and suppose nonnegative integer key (10)
values are hashed into the table using the hash function hl( ):
Suppose that collisions are resolved by using linear probing. The integer key values
listed below are to be inserted, in the order given.
43,23,1,0,15,31,4,7,11,3
Show the home slot (the slot to which the key hashes, before any probing), the probe
sequence (if any) for each key, and the final contents of the hash table after the key
values (shown above) have been inserted in the given order.
Q.2 RATING SUMMATION PROBLEM: Robin is an extremely biased person, and he dislikes (10)
people who fail to solve all the problems in the interview he takes for hiring people.
There are n people on a day who came to be interviewed by Robin.
Robin rates every candidate from 0 to 10. He has to output the total ratings of all the
people who came in a day. But, here's the problem: Robin gets extremely frustrated
when someone ends up scoring a 0 in the interview. So in frustration he ends up
removing the candidate who scored that 0, and also removes the candidate who came
before him (not already removed). If there is no candidate before the one who scores a
0, he does nothing.
Input format: The first line of input contains an integer — n (total no. of people who
came for interview). The next line contains integers, (where the ith integer
represents the rating of the ioil person.) separated by spaces.
Output: You've to find the summation of all the ratings in a day for Robin (Note: Don't
add scores of removed candidates).
a) Which data structure can be best applied for the above mentioned problem?
b) Write down the algorithm to solve above problem (assuming the coding of primitive
operations already exists).
c) What will be the total sum of rating for the following input:
22
2 3 0 7 0 9 4 0 6 0 8 2 0 0 5 0 0 9 2 0 0 6
Page 1
Q.3(a) Calculate and justify the time complexity of following function fun (). Assume that (4)
log(x) returns log value in base 2.
void fun()
i int i, j;
for (i=1; i<=n; i++)
( for (j=1; j<=log(i); j++)
printf("comploxity");
Q.3(b) Write down the recursive algorithm for computing Factorial of a number 'n'. Analyze (6)
the complexity of the algorithm by writing and solving the recurrence relation for the
algorithm.
Q.4 What is the difference between Prim's algorithm and Kruskal's algorithm for finding (10)
the minimum-spanning tree of a graph? Execute Kruskal's algorithm on the graph
shown in Fig. 1.
(Fig. 1)
Q.5 Given two string sequences, write an algorithm to find the longest common (10)
subsequence and its length using dynamic programming. Apply the algorithm to
following two sequences:
Q. 6(a) Consider n jobsji, ,2, ,n each has an associated deadline di, d2, d„ and profit pi, 132, ...
(5)
pn. Profit will only be awarded or earned if the job is completed on or before the
deadline. Assume that each job takes unit time to complete. Apply the greedy
algorithm (show detailed steps) to the following set of 6 jobs and their associated
deadline and profits to earn maximum profit when only one job can be scheduled or
processed at any given time.
Jobs 1 2 3 4 5 6
Deadline 2 1 3 2 1 3
Profit 55 40 30 75 60 25
Page 2
Q7(a) Use the quick sort algorithm and show the steps to sort the following list of elements. (4)
9 7 5 11 12 2 14 3 10 6
Q7(b) Calculate the complexity of quick sort using recursion tree method for the following (6)
cases:
i. Worst case ii Best case
Q.8 Make a Binary Search Tree for the following sequence of numbers and write the (10)
preorder, inorder and postorder traversal of the tree.
45, 36, 76, 23, 89, 115, 98, 39, 41, 56, 69, 48
Q9(b) Write any two advantages and two disadvantages of doubly linked list over single (2)
linked list.
Q.10 Apply BFS and DFS on the directed graph given in Fig. 2 using vertex 3 as source (10)
showing all the intermediate steps.
(Fig. 2)
Page 3