MA60002 Data Structure and Algorithms (Bhakt)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DEPARTMENT OF MATHEMATICS, IIT - Kharagpur

Mid Semester Examination (Spring 2016)


MA 60002 Data Structure and Algorithm
No. of students: 90 Total Points: 30 DURATION: 2 Hours

Answer ALL QUESTIONS. All the notations are standard and no query or doubts will be
entertained. If any data/statement is missing, identify it in your answer script. Marks are
indicated at the end of each question.

l. Consider the recurrence T(n) = T(n/2) + T(n/4) + n. Use the substitution method to
give a tight upper bound on the solution to the recurrence using O-notation. [2)

2. For each of the following algorithms, (i) give a recurrence that describes its worst-case
running time and (ii) its worst-case running time using 8-notation: (a) Binary search, (b)
Insertion Sort, (c) Merge Sort, (d) Randomized quicksort and (e) Strassen's algorithm. [5)

3. Consider the following sorting methods: Insertion Sort, Merge Sort, and Quick Sort. What
is the running time using O-notation for each method

(a) When all the the array values are equal?


(b) When the values are in order?
(c) When the values are in reverse order? [3)

Explain your answers.

4. a) Is the sequence (20, 15, 18, 7, 9, 5, 12, 3, 6, 2) is a max-heap? Explain.


b) Where in a max-heap can the smallest element reside, assuming all elements are distinct?
Include both the location in the array and the location in the implicit tree structure.
c) Suppose that instead of using Build-Heap to build a max-heap in place, the Insert
operation is used n times. Starting with an empty heap, for each element, use I nsert to
insert it into the heap. After each insertion, the heap still has the max-heap property, so after
n Insert operations, it is a max-heap on the n elements.
(i) Argue that this heap construction runs in O(nlogn) time.
(ii) Argue that in the worst case, this heap construction runs in D(n logn) time.
(d) Insertion sort can be expressed as a recursive procedure as follows. In order to sort A[1 .. n], we
recursively sort A[1 .. n-1] and then insert A[n] into the sorted array A[1 .. n - 1]. Write a
recurrence for the running time of this recur ive version of insertion sort. [6)

5. (a) Write a pseudo-code for finding the k-th largest element in an array of n elements in
linear time without using any extra storage.
(h) Illustrate the above algorithm on the following sequence by finding the 3-rd largest
element:
13,14,15,16,17,12,11,10,9

(c) Explain why the average computing time of the above algorithm is linear. [2 + 1 + 1)

--P.T.O.--
6. (a) Use the integer hash function h(x) = x mod 11 and table size 11. Using chaining with
separate lists, show the location in the hash table for each integer value in the following
sequence:
7,21,45,40,65,98,44,67

(b) Use the same hash function and give the table constructed by the linear probe method.

(c) What is perfect hashing? [4]

7. TRUE OR FALSE? If the statement is correct, briefly state why. If the statement is
wrong, explain why. [6]
(a) By the master theorem, the solution to the recurrence T(n) = 3T(n/3) + log2 n is
T(n) = 8(nlog2n).

(b) Let Fk denote the k-th Fibonacci number. Then, the n2th Fibonacci number Fn2
can be computed in o (1og2n) time.

(c) There exists a comparison sort of 5 numbers that uses at most 6 comparisons in the
worst case.

(d) Let S be a set of n integers. One can create a data structure for S so that determining
whether an integer x belongs to S can be performed in 0(1) time in the worst case.

(e) Suppose that an array contains n numbers, each of which is -1, 0 or 1. Then, the array
can be sorted in O(n) time in the worst case.

() Let AI, A2 and A3 be three sorted arrays on n real numbers (all distinct). In the
comparison model, constructing a balanced binary search tree of the set Al U A2 U A3
requires Q( n log2 n).

--- The End--

You might also like