Uploaded by 949996504

TUT answer

advertisement
Tutorial 8 – Computational Complexity
1. Give an example of an algorithm that we have seen in this course that does not run
in polynomial time.
Examples are:
“the brute force algorithm that solves Max Independent Set, running through all
possible subsets of vertices in the graph” runs in time O(2^n), on a graph with n
vertices…
“the recursive backtracking algorithm for Sudoku – in the worst case, if we have to
backtrack through all possible solutions” runs in time O((n^2)^n) for a board of size
n…
“the recursive algorithm to find the value of nth Fibonacci number -takes time
proportional to the nth Fibonacci number itself” runs in time more than O(2^(sqrt
n)), less than O(2^n)…
2. The 3-SAT problem takes a formula on n Boolean variables, in 3CNF form, as input
and determines whether or not the formula has a satisfying assignment. Show that
this problem is in the class NP.
Given a proposed Boolean assignment to the n variables, for each true or false, how
can we determine if this assignment makes the given formula true? Run through
each clause and decide whether or not the clause is true, according to the variable
assignment. This can be done in time = n x (number of clauses in the formula.) So, we
have a certifying algorithm that runs in time p(n.m) – where m = number of clauses
in the formula. So, we have a certifying algorithm that runs in time polynomial in the
size of the input = a formula on m clauses using n Boolean variables.
3. The Closest String problem takes as input n strings of length m, and an integer k, and
asks whether there is a string within Hamming distance k of all the input strings. The
Hamming distance between two strings of equal length is the number of positions at
which the corresponding symbols are different. Show that this problem is in the class
NP.
Given a proposed solution string S of length m, how can we determine if S is within
Hamming distance k of all the input strings? Run through each input string and
decide whether or not the proposed solution string S is within Hamming distance k
of that string i.e. differs in at most k positions. This can be done in time = n x m. So,
we have a certifying algorithm that runs in time p(n.m) – where m = length of the
input strings, n = number of input strings. So, we have a certifying algorithm that
runs in time polynomial in the size of the input = n strings of length m.
4. The Max Cut problem takes a graph as input and one wants to find a subset S of the
vertex set such that the number of edges between S and the complementary subset is
as large as possible. Consider a decision version of this problem, where we are given
a graph and an integer k and we have to decide if there is a subset S of the vertex set
such that the number of edges between S and the complementary subset is at least k.
Show that this decision problem is in the class NP.
Given a proposed subset S of the vertices in the graph, how can we determine if the
number of edges between S and the complementary subset is at least k? Run through
each edge in the graph and determine if the edge has one end point in S, the other in
G(V)/S. This can be done in time = m (the number of edges in the graph, which is
bounded above by (n^2)). So, we have a certifying algorithm that runs in time p(n) –
where n = number of vertices in the graph. So, we have a certifying algorithm that
runs in time polynomial in the size of the input = n vertices.
5. Explain how you can use this decision problem to solve the Max Cut problem.
Suppose that you have a (hypothetical) algorithm that solves the decision problem.
Using this, ask “does the graph have a subset S where the number of edges between
S and the complementary subset is at least 1?” “does the graph have a subset S where
the number of edges between S and the complementary subset is at least 2?” and so
on… the last “yes” answer, before you get a “no” is the max cut number for the
input graph.
Once you find the max cut number, call this “mcn”, you can then ask, “removing
vertex 1, does the new graph G/(v1) have a subset S where the number of edges
between S and the complementary subset is at least mcn?” if no, then v1 must be in
every such subset S, if yes, then we can remove v1 and repeat with the next vertex.
Run though each vertex in turn, until you are left with a subset of the vertices that
must be included in S.
Note that this algorithm for Max Cut (where we actually find a subset that gives the
Max Cut possible) asks p(n) questions of the decision algorithm, where n = number
of vertices in the input graph.
6. Suppose that problem A polynomial-time reduces to problem B, in other words, we
can
find a polynomial time algorithm that uses solutions to instances of problem B (given
by an oracle - aka “fairy godmother”) to solve problem A.
1. If problem A can be shown to be NP-complete, what does that tell us about
problem B?
Problem B must be NP-hard - problem A can be solved using a polynomial
number of instances of the (hypothetical) algorithm for problem B. If problem
A is NP-complete – then, we have already established that any other problem
in NP can be reduced to problem A (using a polynomial-time reduction
algorithm), and therefore can be reduced to problem B…
2. If problem B can be shown to be in P, what does that tell us about problem A?
Problem A must be in P - problem A can be solved using a polynomial
number of instances of the (hypothetical) algorithm for problem B. In this
case, each of those instances can be solved in polynomial time. This gives us a
polynomial-time algorithm to solve problem A.
7. The Travelling Salesperson problem takes a graph with non-negative weights on the
edges, and an integer k, and asks whether or not the graph contains a tour of cost at
most k. A tour is a simple cycle containing all the vertices (exactly once) and the cost
of the tour is the sum of the costs of the edges in the cycle. Show that this problem is
NP- complete.
1. First show that this problem is in the class NP.
Given a subset of the edges in the graph, of size n, and an ordering on those
edges, we can determine if this gives a tour of cost at most k by checking 1.
for each edge in the ordering, it shares one endpoint with the next edge in the
ordering, and the other endpoint with the previous edge in the ordering
(wrapping around from n to zero) 2. each vertex is included exactly once as
an endpoint shared between two edges 3. the sum of edge weights is at most
k. We can check all of this in time p(n) where n = number of vertices in the
graph.
2. To show that the problem is NP-complete, you have a second job to do - find
another NP-complete problem which reduces to this problem. Try to show that
the another NP-complete problem which reduces to this problem. Try to show
that the Hamiltonian Cycle problem (which is NP-complete) reduces to the
Travelling Salesperson problem. The Hamiltonian Cycle problem takes as input a
graph G (with unweighted edges) and asks for a tour of the vertices that visits
each vertex exactly once and then returns to the first vertex. Hint: given a graph
G, for which we want to determine "does G have a Hamilton cycle?", create a new
graph G' with edges weighted one or two. Now consider what a tour of weight at
most n (the number of vertices in the graph) must look like. How does this solve
your instance of the Hamiltonian Cycle problem for G?
Given a graph G = (V,E) (with unweighted edges) for which I want to
determine “does G contain a Hamilton Cycle?” do the following:
Create a new graph G’ = (V’, E’), where V’ = V, E’ = all edges between pairs
(v1, v2) in V. The edges in E’ that are also in E get weight 1, the other edges
get weight 2. Ask “is there a TSP tour of weight at most n in G’?” The tour
will need to use exactly n edges. If yes, then this tour must use only edges
weighted 1, i.e. edges in E, so this gives a Hamilton Cycle in G. If no, then no
set of edges in E gives a Hamilton Cycle in G.
Download