Sample Algorithms Test 1
Question 1. (25 points)
Solve the following recurrence relation to get the general solution. You DO NOT need to solve for the ci constants. You may assume that n is a power of 5, i.e., n = 5k and log 5 n = k.
T(n) = 7T(n/5) - 12T(n/25) + n (log 5 n)2 + 3log 5 n, for n > 1.
Question 2. (25 points) for i := 1 to n do j := n while j 1 do for k := i to j do < something of > end for j := j / 4 end while end for
Analyze the above algorithm to determine its theta notation, , or its best O( ) notation.
Assume that n is a power of 4.
Question 3. (10 points) Suppose that you have an algorithm that required 10 seconds to run on a problem size of 1000. How long would you expect the algorithm to run on a problem size of 10,000? (If you don't have a calculator, just write an equation for the answer.)
Question 4. (40 points)
Let A be an array indexed from 1 to n. Also, let A contains n different integer values that are sorted in ascending order (from smallest to largest). Give a divide-and-conquer algorithm that finds an index i such that A[i] = i (if one exists) and runs in O(log2 n) time. If such an index does not exist, then it should return -1. (Give an English description or a high-level language (C++, Ada, etc.) algorithm.)