Final exam

advertisement
CS 601 Final Exam
Fall 2004
Name ______________________________
Each of these 8 problems is worth 20 points. You may attempt all 8 if you wish.
1. Solve each of these recurrences to obtain T(n) as a  function of n. It is not
necessary to write the justification for your answers.
a. T(n) = 64 T(n/2) + n3
b. T(n) = 64 T(n/4) + n3
c. T(n) = 64 T(n/8) + n3
d. T(n) = T(n) + 1
e. T(n) = T(lg n) + 1
2. You are given n activities with start times s1, s2, ..., sn and finish times f1, f2, ..., fn.
Design and analyze an efficient greedy algorithm that determines the largest subset of
activities that all overlap each other. That is, each activity in this subset must overlap
every other activity in the subset.
3. You are given a weighted directed graph G =(V,E) such that each edge (x,y) has
a positive length W(x,y). Let D(x,y) denote the shortest distance from x to y for
all pairs x and y. For each problem below, write a recursive formula that computes
the specified values for all pairs x and y. It is not necessary to convert each recursive
formula into a dynamic programming algorithm.
a. Number(x,y) = the number of different shortest paths from x to y.
b. MostEdges(x,y) = the most edges along any shortest path from x to y.
4. Let (k) denote the number of divisors of k. For example, (20) = 6, because 20
has these 6 divisors: 1, 2, 4, 5, 10, 20. Analyze the running time of a sequence of n
operations, such that the kth operation takes time (k) for 1  k  n. Determine the
amortized cost per operation, and briefly justify why your answer is correct.
5. Given n points (x1,y1),…,(xn,yn), design a (n)-time algorithm that determines
whether or not these n points can form the consecutive vertices of a convex polygon.
6. Prove that this Nearest Return Travel problem is NP-complete:
Input
List of distances d1, d2, …, dn, and integer R.
Question Is it possible to start at the origin point (x=0,y=0) and for 1  k  n
move dk units toward either the east (increase x by dk), west (decrease x
by dk), north (increase y by dk), or south (decrease y by dk), such that
after all n moves, the final location is within a distance of at most R units
from the origin?
7. Prove that this Graph Coloring problem is NP-complete:
Input
Graph G =(V,E) and integer k.
Question Does there exist a function C: V {1,…,k} such that C(x)C(y) for
every edge (x,y)E? Such a function C would be called a k–coloring.
Hints: Justify why it is impossible to properly 3-color the subgraph drawn below
such that the vertices W, X, Y, Z all receive the same color. Utilize this subgraph to
provide a reduction from the 3-Satisfiability problem.
W
Y
X
Z
8. Consider this proposed greedy algorithm for the vertex cover problem: Choose any
vertex v that is incident to the most edges, and add vertex v to the cover. Remove all
edges that are incident to v, and repeat until no edges remain. The set of chosen
vertices forms the vertex cover. First prove that this greedy algorithm is not always
optimum. Second prove that this greedy algorithm is not 2-approximate. [Hint: The
smallest counterexample is a graph with 19 vertices that yields a ratio of 13/6.]
Download