CS447/CS547/EE667 Homework 5 - due Thursday October 22, 2009 ------------------------------------------------------------ 1. Solve the following recurrence equations: A. T(n) = 4T(n/2) + n B. T(n) = 4T(n/2) + n^2 C. T(n) = 4T(n/2) + n^3 Don't forget to show how you got the answer. 2. Chapter 5, Problem 3 You can view the question this way: You have an array of elements. You need to write a function that will take the array, a starting index position and a stopping index position, as arguments, and returns the following: If there is some element k that appears in the array more than n/2 times, return k. If there is no element that occurs more than n/2 times in the array, return nil. But there is a trick to this problem. The only comparison of the elements in the array you can use is to compare if two elements are equal. You cannot compare two elements to see if one is greater than the other one. Your function must run in O(n lg(n)) time. 3. A. Consider the following recursive sorting algorithm: Sort(A) ------ If the first element of A is larger than the last element, then swap them If the array contains more than two elements Recursively sort the first two thirds of the array Recursively sort the last two thirds of the array Give the running time of this algorithm. Of course, you must show how you calculated it. Give an example to show that it will not correctly sort an array. B. Consider the following recursive sorting algorithm: Sort(A) ------ If the first element of A is larger than the last element, then swap them If the array contains more than two elements Recursively sort the first two thirds of the array Recursively sort the last two thirds of the array Recursively sort the first two thirds of the array Give the running time of this algorithm. Of course, you must show how you calculated it. Extra Credit: Prove the algorithm is correct. You prove it by induction. The base case is easy. For the inductive step, assume the recursive calls sort correctly, and prove that the entire algorithm must then be correct. You should consider two elements x and y in the array, with x < y. Show that x will always end up earlier in the array than y. There are several cases to consider. 4. In the algorithm SELECT which I did in class, the input elements are divided into groups of 5. Will the algorithm work in linear time if they are divided into groups of 7? Argue that SELECT does not run in linear time if groups of 3 are used. Of course, you need to give arguments to support your answers.