Algorithms

Question 1 (20 points) Design a divide and conquer algorithm that returns the height of an input binary
tree with š¯‘› nodes. Analyze the running time of the algorithm.
Question 2 (20 points) Design a divide and conquer algorithm that returns a pair (x, y), where x is the
largest number and y is the second largest number in an array of n numbers. Analyze the running time of
the algorithm.
Question 3 (15 points) Consider the following modification of the algorithm Merge Sort. The
algorithm first divides the input array A[low..high] into four parts A1,A2,A3, and A4 instead of two. It
then sorts each part recursively, and finally merges the four sorted parts to obtain the original array
in sorted order. Assume for simplicity that n is a power of 4. Analyze the modified Merge Sort
algorithm running time.
Question 4 (20 points; 10 points; 10 points) Find the time complexity of the Select algorithm if it
divides the array A into q groups of:
a) 4 elements.
b) 7 elements.
Question 5 (15 points) Apply the Quick Sort algorithm on the array
A = [32, 65, 40, 11, 18, 29, 37, 32, 53]
Clearly show the pivot and the subarray contents after the split terminates.
Question 6 (10 points) What is the running time of Quick Sort algorithm when all elements of array
A have the same value?

Powered by WordPress