Q1: 10 points Q2: 10 points Q3: 20 points Q4: 20 points Q5: 25 points Q6: 15 points Total: 100 points
True or false with justification: Let A be an algorithm that operates on a binary tree, without changing the tree, as follows: A first spends O(1) time processing the root node of the tree, then recursively calls A on the left and the right subtrees. Then A can be substantially sped up on general binary trees using dynamic programming.
True or false with justification: Let k be any positive integer constant greater than 1 . Then the recurrence T(n) = kT(n/k) + O(n), with T(1) = O(1), has the same big-O solution for any such k. (You may assume that T(n) is evaluated only when n is a power of k.)
Consider the following Java method (assume that it will only be called with 0 ≤ k and k ≤ n):
int choose (int n, int k) {
if ((k == 0) || (k == n)) return 1;
return choose (n-1, k) + choose (n-1, k-1);}
Explain why the running time will not be polynomial in n in general. Describe (in code or in English) how to revise the algorithm to be polynomial time in n. Carefully determine and justify a big-O bound on the running time of your improved version.
Let G be a directed graph and let s1,...,sk and t1,...,tk be any 2k distinct vertices of G. We want to know whether there exist k paths P1,...,Pk such that:
Describe an algorithm to solve this problem in a time that is polynomial in m, the number of edges in G. Determine the big-O running time of your algorithm in terms of m, n (the number of vertices in G) and k (the number of paths to be found).
Consider the following algorithm strangeSort, which sorts n Comparable
items in a list A:
Let G be a directed graph with exactly one source s, exactly one sink t, and a positive integer capacity on each edge. Explain carefully why we know that there is a maximum-size flow in G from s to t that sends an integer flow over each edge of G.
Last modified 3 November 2006