# CMPSCI 311: Theory of Algorithms

### Actual final exam (120 min) is Tuesday 16 December 2003

Directions: There are 150 total points. Each of the first four questions is a statement that may be true or false. Please state whether it is true or false -- you will get five points for a correct boolean answer and there is no penalty for a wrong guess. Then justify your answer -- the remaining points will depend on the quality and validity of your justification.

• Question 1 (10): (true/false with justification) Let A, B, and C be decision problems and let "≤" denote poly-time reducibility. If A ≤ B and B≤ C, then A ≤ C must be true.

• Question 2 (10): (true/false with justification) Let f and g be functions. If f is in the class o(g), then f+g is in the class Θ(f).

• Question 3 (10): (true/false with justification) Let G be a directed graph given by its adjacency matrix. We say that a vertex v in G is special if (u,v) is an edge for every vertex u. Determining whether a given vertex v is special requires Θ(n) time.

• Question 4 (10): (true/false with justification) If A and B are both decision problems in the class NP, then A ≤ B and B ≤ A cannot both be true. (Again, "≤" denotes poly-time reducibility.)

• Question 5 (30): Consider n items stored in a min-heap. The items may only be moved and compared to one another. Moves and comparisons take O(1) time each.

• (a,10) Explain how to create, from this heap, an array that has all n items in sorted order, using O(n log n) time. Justify your time bound carefully.

• (b,20) Explain why such a sorted array cannot be created from the heap in o(n log n) time.

• Question 6 (50): Suppose we are given an n by n matrix of booleans called A, denoting a binary relation, and we want to compute the n by n matrix of booleans B that denotes the reflexive transitive closure of this relation. Let m be the number of entries of the matrix that are "true".

• (a,10) Carefully describe a reinterpretation of this problem in terms of a directed graph -- what information about the graph is given and what information is asked for?

• (b,10) Explain how to find B by matrix powering. What is the running time of this method, assuming the ordinary and not the Solovay-Strassen method is used to multiply matrices?

• (c,15) Explain how dynamic programming can be used to improve this time asymptotically (by Warshall's algorithm). What is the new running time?

• (d,15) Suppose m is in the class o(n2). Explain how to determine B asymptotically faster than by Warshall's algorithm. State and justify the new running time in terms of n and/or m.

• Question 7 (30): Suppose we are given an array of n integer values and we want to decide whether they are an arithmetic progression when viewed as a set. An arithmetic progression is defined to be a set of the form {a,a+b,a+2b,...,a+(n-1)b} for some integers a and b. Thus, our decision problem is to determine whether when sorted, the array is in this form.

• (a,15) Show that this decision problem is in the class NP by describing an NP-procedure that can possibly return "true" if and only if the actual answer is "true". Your evaluation phase should take only O(n) time.

• (b,15) Explain how to solve this decision problem in O(n) time (with an ordinary algorithm, not an NP-procedure).