National Institute of Technology Rourkela
National Institute of Technology Rourkela
NOTE: Answer any TEN questions. Full Marks: 30 ; All question carry equal marks.
2. (a) Two algorithms take n2 days and 2n seconds respectively to solve an instance of size n. What
is the smallest instance on which the former algorithm outperforms the latter? Approximately
how long does such an instance take to solve?
(b) Consider a variation of the binary search algorithm so that it splits the input not only into two
sets of almost equal sizes, but into two sets of sizes approximately one third and two-thirds.
Write down the recurrence for this search algorithm and find the asymptotic complexity of
this algorithm?
(c) The worst case running time of merge sort is O(n log n). What is its best-case time? Can we
say that the time for merge sort is Θ(n log n)?
3. A max-min algorithm finds both the largest and smallest elements in an array of n values.
Design and analyze a divide-conquer max-min algorithm that uses ⌈3n/2⌉ − 2 comparisons for
any integer n, where n is a power of 2.
4. Write the control Abstraction for Divide-and-Conquer. Find the solution to the equation:
T (n) = a T (n/b) + Θ(nk ), where a > 1 and b > 1 with if a = bk .
5. Suppose an array A consists of n elements, each of which is red, white, or blue. We seek to sort
the elements so that all the reds come before all the whites, which come before all the blues.
The only two operations permitted on the keys are
[1] Examine(A,i) report the color of the ith element of A,
[2] Swap(A,i,j) swap the ith element of A with the j th element.
Find a correct and efficient linear-time algorithm for red-white-blue sorting.
CONTINUED
–2– CS332
6. It is suggested that MERGE SORT is not a good strategy for arrays of size less than about 8
to 16, for which ”INSERTION SORT” may be better. Realizing that in our MERGE SORT
algorithm, it is the arrays of small sizes which are handled very often, it may be a good idea to
modify our MERGE algorithm so that when the size of an sub-array is less than, say 8, it is not
split further, but is sorted by INSERTION SORT. Write the modified merge sort algorithm,
and compute the time complexity from the appropriate recurrence relation, assuming that
insertion sort takes a fixed time d.
7. What do you mean by principle of optimality? What is its significance in algorithm design?
What are the four basic steps to design a dynamic programming algorithm? Define Matrix
chain multiplication as an optimization problem? Outline the dynamic programming algorithm
to compute optimal parenthesized expression
9. Briefly describe the basic idea of quick sort. What is the complexity of quick sort? Analyze
the average-case complexity solving the recurrence relation.
10. Find the complexity of the Strassens matrix multiplication algorithm in terms of both the
multiplication operations and the addition operations. Assume that the matrices that are
multiplied are square n × n matrices and n is a power of 2. (Do not write the algorithm;
just calculate the complexity. Also, do not write only the result; show the calculation step by
step.) Prove that if n is not a power of two, then the complexity (in terms of multiplication
operations) is at most 7 ∗ f (n), where f (n) is the complexity (of multiplication operations)
you have obtained as above.
11. Consider the modified binary search algorithm so that it splits the input not into two sets of
almost-equal sizes, but into three sets of sizes approximately one-third. Write the algorithm
for this ternary search, use the recurrence relation of ternary search algorithm to compute the
asymptotic complexity.
12. Given a sorted array of distinct integers A[1...n], you want to find out whether there is an
index i for which A[i] = i. Given a divide-and-conquer algorithm that runs in time O(log n).
13. Given an array A of n integer elements, how would you find the second smallest element in
n + log2 n comparisons.
14. Devise a Divide-and-Conquer Algorithm for computing the kth largest element in an array of
n integers, that runs in time O(n).
15. You are given a collection of n bolts of different widths and n corresponding nuts. You are
allowed to try a nut and bolt together, from which you can determine whether the nut is larger
than the bolt, smaller than the bolt, or matches the bolt exactly. However there is no way to
compare two nuts together or two bolts together. The problem is to match each bolt to its
nut. Design an algorithm for this problem with average case efficiency of Θ(n log n).