Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
COT 5405: Algorithms Spring 2003 Due Date: 06/02/2003, 5pm Homework Assignment 1. Please use Divide-and-Conquer approach to solve each of these problems (unless indicated otherwise). Also, you are expected to derive the best possible algorithm to solve the problem (unless indicated otherwise). Poor performance solutions (even if they are correct) may not get any credit. Divide your solution into four parts: 1. High Level Algorithm 2. Pseudo Code (or code in any high level language such as Java, C, C++) 3. Proof of Correctness 4. Complexity Analysis Please write legibly. 1. (10 points) Solve the recurrence relation iteratively (not using the Master’s theorem): T (N) = 2T ( N /2 ) + log N Make any reasonable assumptions. Find an exact formula for T (N), and then give a Theta expression. 2. (10 points) Suppose T(N) = T(N-1) + T(N-2) + 1 and T(1) = T(0) = 1. Prove that T(N) = (FN+1) where FN+1 represents Fibonacci sequence. 3. (10 points) Show that Fn >= (3/2)n-2 for all n >= 1 where Fn denotes the n-th Fibonacci number. In other words, prove that Fn = ( (3/2)n-2 ), which means Fibonacci numbers grow exponentially fast. 4. (10 points) The MCSS (Maximum Contiguous Subsequence Sum) problem is defined as finding the maximum contiguous subsequence in a sequence of numbers (positive, negative, or zero) that gives the highest sum. Say, for a sequence [ 1, 12, -2, -15, 10] the MCSS is [1,12]. Null subsequence ( [ ] ) has a sum of zero, and sometimes even this can be the MCSS, in case there are a lot of negative numbers. The following is the implementation of a recursive algorithm to solve the MCSS problem. Theoretically analyze this algorithm. Does this algorithm give the correct result? If yes (proof not required), state the corresponding recurrence relation and solve it to give a Theta expression. Else, give a counterexample to prove that this is not always correct. int A[] = {-2, 11, -4, 13, -5, 2}; // The current largest run starting from A[n] heading west. int largestRunHeadingW = 0; // The current largest run (anywhere) which is the desired output. int largestRunAnywhere = 0; void maxSubsequenceSumX(int n) { if (0 == n) largestRunHeadingW = largestRunAnywhere = max (0, A[0]); else { maxSubsequenceSumX(n-1); largestRunHeadingW = max(0, largestRunHeadingW + A[n]); largestRunAnywhere = max(largestRunAnywhere, largestRunHeadingW); } } int main() { maxSubsequenceSumX(5); cout << "The largest run sum is " << largestRunAnywhere << "."; } 5. (15 points) This is the Skyline algorithm. You have the two-dimensional so-called “X-ray image” of the outlines of the skyscrapers in a city. That is, for every building, you have three entries: two on X-axis outlining its breadth on the city landscape, and one entry on the Y-axis giving the height of the building. Design an efficient algorithm that will give the skyline in the form of alternate entries on x-axis and y-axis. 6. (15 points) You are an ESPN reporter who is writing a piece on the disparity of wages among the NFL players. (For those not familiar with NFL, it has two conferences: the National Conference and the American Conference – both with equal number of teams, and say all the teams have equal number of players). You have two lists of the players with their wages (one list for each of the conferences), with players positioned in the lists according to their wages (you can pick up the i-th ranked player instantly). You need to find out the player who is really in the middle as per wages (so that the number of NFL players making more or less than him are the same). Design an efficient algorithm to find the player (or, two players since we are talking about even number of players at NFL). 7. (15 points) Can the master’s theorem be applied to the following recurrence? T(n) = 4T(n/2) + n2 log n? Why? Give an asymptotic upper bound for this recurrence. 8. (15 points) Consider the following problem. You have an n x n matrix A[i, j], 1<= i, j<=n. Suppose that each row and column of A is sorted. I.e., for a fixed i, A[i, j] increases with j and for a fixed j, A[i, j] increases with i. Input: a number x. Output: “yes” if x is in A, “no” otherwise. Design an efficient Divide-and-Conquer algorithm. (Note: O(n2) time algorithm is not acceptable).