Q1: 10 points Q2: 10 points Q3: 15 points Q4: 15 points Q5: 20 points Q6: 20 points Q7: 15 points Q8: 15 points Total: 120 points
True or false with justification: Let A be an algorithm that operates on a list of n objects, where n is a power of two. A spends Θ(n2) time dividing its input list into two equal pieces and selecting one of the two pieces. It then calls itself recursively on that list of n/2 elements. Then A's running time on a list of n elements is O(n).
FALSE. The time taken on a list of n elements is at least the Θ(n2) time taken before the recursive call. Since this is Θ(n2) rather than just O(n2), it is Ω(n2). Thus the total time is Ω(n2), and a function cannot be both Ω(n2) and O(n).
True or false with justification: Let X be a decision problem. If we prove that X is in the class NP and give a poly-time reduction from X to 3-COLORING, we may conclude that X is NP-complete.
FALSE. This would be true if the reduction were from 3-COLORING to X, for example. But as stated, X might be a language in P (since P is contained within NP, and any P problem can be reduced to 3-COLORING as 3-COLORING is NP-complete). If X were both in P and NP-complete, it would follow that P=NP. Since the given statement implies P=NP, we cannot conclude that it is true.
Let G be an undirected graph with n vertices and m edges, given as an adjacency list. Each vertex has a postive integer value, and one vertex is s designated as the start point. Our goal is to select one vertex v in the graph, travel to it, and collect its value minus the cost of traveling from s to v. In this problem the cost of traveling is 1 for each edge traversed.
Describe an algorithm, running in O(n+m) time, to determine which vertex v maximizes our net reward. Explain why your algorithm takes O(n+m) time.
We run a breadth-first search, taking O(n+m) time, and find the distance d(v) from s to v (measured in number of edges) for each vertex v. Then in O(n) time we calculate value(v) - d(v) for each v, and find the v that minimizes this value. The total time is O(n+m) + O(n) = O(n+m).
This question is the same as Question 3 except that now each edge has its own positive integer cost, and to travel to a node we must pay the sum of the edge costs for the edges we use. We are no longer required to find the best vertex in O(n+m) time.
Describe an algorithm to find the best vertex that uses a time that is polynomial in n and m, no matter what integers are used for the edge and vertex costs. (You may assume that arithmetic on these costs takes only O(1) time per operation.) State and justify a polynomial bound on the running time of your algorithm.
Here we can no longer use BFS to find the minimum-cost path to each vertex, but we could use Dijkstra's algorithm because there are no negative edge costs. We inductively build a set of vertices for which we know the minimum paths, and maintain a priority queue among the vertices that are adjacent to a vertex in this set but not in that set. For each of the n vertices, we remove the lowest-cost element in the queue, add it to our set, and update the costs for every neighbor of that new element that is not in the set. This takes O(1) priority queue operations, and hence O(log n) time, for each vertex in the graph and for edge in the graph (since there is exactly one pair of a node and its neighbor found in this process for each edge). The total time is thus O((m+n) log n), which is bounded above by a polynomial in n and m.
The Global Max-Cut problem is a variation of the Max-Cut problem that we studied in connection with network flow. Our input is a undirected graph G with n vertices, m edges, and a positive integer weight on each edge. We want to find the largest possible cut (A,B) in G, where A and B are disjoint non-empty sets of vertices with A ∪ B = V (the set of all vertices). There are two differences between this problem and the Max-Cut problem we studied -- the graph is undirected, and there are no designated vertices s and t that must be on opposite sides of the cut.
Give a deterministic (not randomized) algorithm to solve this problem in a time that is polynomial in m and n, whatever the weights on the edges. You may refer to the standard algorithms for the Max-Cut problem, but indicate exactly how you will use them to solve this problem given the differences noted above. State and justify a polynomial time bound on your algorithm.
Note: This problem is solved in Section 13.2 of KT, which we didn't cover in lecture -- don't look there if you want to solve the problem yourself.
Pick an arbitrary vertex s. Any such cut (A,B) must have s in one set and
at least one vertex in the other. For each vertex t other than s, we can use
ordinary network flow to find the largest cut that has s on one side and t on
the other. (To do this we must take the undirected graph G, make it directed
by converting each undirected edge into a directed edge in each direction, and
then make s a source and t a sink by removing all edges into s or out of t.)
The largest of the n-1 cuts we find in this way must be the global maximum
cut, since that maximum cut must separate s from t for at least one choice of
t and will be the maximum cut found when we use that value of t.
The running time of this algorithm is n-1 times the time for the network
flow algorithm, plus O(n) to find the maximum of the n-1 values. (Actually
we should add in O(n2), because we may have to write down each of
the n-1 different cuts to have the right cut available at the end.) If we
can't make assumptions about the value of the edge weights, we need to use the
Edmonds-Karp method to find our augmenting paths. It is stated but not proved
in the book that this method takes at most O(mn) phases to find a maximum flow
and a minimum cut, or O(m2n) time. We multiply this by n-1 to
account for the different values of t, to get O(m2n2)
total time. Section 13.2 of KT explains the Karger randomized algorithm which
solves this problem (with high probability) in O(nm2) time.
This question and the two following refer to the Dominating Set problem. In an undirected graph G, a dominating set is a set X of vertices such that every vertex in G is either in X or connected to a vertex of X by an edge, or both. The Dominating Set problem is to input an undirected graph and a number k, and determine whether there is a dominating set with k vertices.
Prove that the Dominating Set problem is NP-complete. (Hint: Reduce from Vertex Cover by constructing a new graph from G.)
First, Dominating Set is in NP because we can verify that a graph has a
dominating set if we are given the set. The set can be described in a
polynomial number of bits (it is simply a list of at most n vertices), and in
polynomial time we can check that the size of the given set is k and that every
vertex in G is either in the set or connected to an element of the set by an
edge.
For the reduction, given an arbitrary undirected graph G and number k we
need to make a graph H such that H has a dominating set of size k if and only
if G has a vertex cover of size k. (This will reduce Vertex Cover to Dominating
Set and complete the proof since Vertex Cover was proved in lecture to be
NP-complete.) (It would be all right if we produced a graph H and a number z
such that H has a dominating set of size z iff G has a vertex cover of size k,
but it turns out that we may take z to be k itself.)
H will have a vertex f(v) for each vertex v of G, and a vertex f(e) for
every edge e of G. (So H has m+n vertices in all.) There is an edge from f(v)
to f(e) in H if and only if v is one of the endpoints of e -- there is also an
edge from f(u) to f(v) if u and v are any two distinct vertices in G. (Thus
the f(v) vertices in H form a clique.)
edges in H.
We claim that there is a vertex cover of size k in G iff there is a
dominating set of size k in H. First assume that the vertex cover in G exists,
as a set X of size k.
Then {f(v): v in X} has size k and is a dominating set of H, because every
f(v) vertex in H is connected by an edge to every other f(v) vertex and thus
to at least one vertex in X, and every edge vertex f(e) is connected by an edge
to f(v) for some vertex v in X because one of e's endpoints must be in X.
Contrariwise, assume that Y is a dominating set of size k in H. If Y
contains any edge-vertices, create a new dominating set Y' by replacing any
vertex f(e) in Y by f(v), where v is either of the endpoints of e. So Y' has
at most k vertices -- it may have fewer if an edge-vertex was replaced by an
already existing vertex. Y' is still a dominating set of H because any
edge-vertex f(e) that we removed from Y is still next to a vertex in Y', and
any vertex-vertex that was next to f(e) is still next to its replacement.
Let X' be the set of vertices v in G such that f(v)
is in Y'. We claim that X' is a vertex cover for G. Let e be any edge in G.
Because Y' is a dominating set, there is some f(v) in Y' that is next to f(e)
in H. Then v is one of the endpoints of e in G, and v is in X'.
A dominating set X for a graph G is defined to be minimal if no proper subset of X is a dominating set. Give a polynomial-time algorithm that inputs a graph G and outputs a minimal dominating set. Argue that your algorithm takes only polynomial time in n, the number of vertices in G.
Let X be the entire set of vertices in G. X is a dominating set because every
vertex is already in it even if there are no edges. We carry out the following:
The set we return is a minimal dominating set by definition. The
procedure may repeat step 1 at most n times because it reduces the size
of X by one each time and a set of size 0 cannot be a dominating set. Thus
the procedure will terminate with a minimal dominating set.
There are at most n phases of the procedure, and in each phase we consider
at most n candidate dominating sets and check each one by finding an endpoint
for at most m edges. The running time is thus O(n2m), which is
O(n4) because m = O(n2). The time is polynomial in n
as desired.
Let d be a positive integer and let G be an undirected graph with maximum degree d. Give a polynomial-time algorithm that produces a dominating set for G that is no more than d+1 times as large as the minimum size dominating set. Argue carefully that your algorithm has this property.
The simplest algorithm is to simply return the entire set of vertices, which
has size n and is definitely a dominating set. The algorithm of Problem 7 is
polynomial time and will return a smaller dominating set (unless G has no edges)
but size n is good enough for our purposes.
This is because in a degree d graph, no set with fewer than n/(d+1) vertices
can possibly be a dominating set. If X is any set of vertices, let Y be the
set of vertices that are in X or connected to a vertex in X. Each vertex in
X can be responsible for at most d+1 vertices being in Y -- itself and at most
d neighbors. So Y's size can be no more than d+1 times the size of X, and if
Y is the set of all vertices then X must have at least n/(d+1) vertices.
Last modified 15 December 2006