








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









So far in the course, we have been building up a“bag of tricks” for solving algorithmic problems. Hopefully you have a better idea of how to go about solving such problems. What sort of design paradigm should be used: divide-and-conquer, greedy, dynamic programming?
What sort of data structures might be relevant: trees, heaps, graphs? What is the running time of the algorithm? All of this is fine if it helps you discover an acceptably efficient algorithm to solve your problem.
The question that often arises in practice is that you have tried every trick in the book and nothing seems to work. Although your algorithm can solve small problems reasonably efficiently (e.g.,
n ≤ 2 0 ) , for the really large problems you want to solve, your algorithm never terminates. When
you analyze its running time, you realize that it is running in exponential time, perhaps n n , or 2 n , or
2 2n , or n! or worse!.
By the end of 60’s, there was great success in finding efficient solutions to many combinatorial problems. But there was also a growing list of problems for which there seemed to be no known efficient algorithmic solutions.
People began to wonder whether there was some unknown paradigm that would lead to a solution to there problems. Or perhaps some proof that these problems are inherently hard to solve and no algorithmic solutions exist that run under exponential time.
Near the end of the 1960’s, a remarkable discovery was made. M any of these hard problems were interrelated in the sense that if you could solve any one of them in polynomial time, then you could solve all of them in polynomial time. This discovery gave rise to the notion of NP-completeness.
This area is a radical departure from what we have been doing because the emphasis will change. The goal is no longer to prove that a problem can be solved efficiently by presenting an algorithm for it. Instead we will be trying to show that a problem cannot be solved efficiently.
Up until now all algorithms we have seen had the property that their worst-case running time are bounded above by some polynomial in n. A polynomial time algorithm is any algorithm that runs in
O( nk ) time. A problem is solvable in polynomial time if there is a polynomial time algorithm for it.
Some functions that do not look like polynomials (such as O(n log n) are bounded above by polynomials (such as O ( n 2 ) ). Some functions that do look like polynomials are not. For example,
suppose you have an algorithm that takes as input a graph of size n and an integer k and run in O( n k ) time.
Is this a polynomial time algorithm? No, because k is an input to the problem so the user is allowed
to choose k= n, implying that the running time would be O( nn ). O( nn ) is surely not a polynomial in n. The important aspect is that the exponent must be a constant independent of n.
Most of the problems we have discussed involve optimization of one form of another. Find the shortest path, find the minimum cost spanning tree and maximize the knapsack value. For rather technical reasons, the NP-complete problems we will discuss will be phrased as decision problems.
A problem is called a decision problem if its output is a simple “yes” or “no” (or you may this of this as true/false, 0/1, accept/reject.) We will phrase may optimization problems as decision problems. For example, the MST decision problem would be: Given a weighted graph G and an integer k, does G
have a spanning tree whose weight is at most k?
This may seem like a less interesting formulation of the problem. It does not ask for the weight of the minimum spanning tree, and it does not even ask for the edges of the spanning tree that achieves this weight. However, our job will be to show that certain problems cannot be solved efficiently. If we show that the simple decision problem cannot be solved efficiently, then the more general optimization problem certainly cannot be solved efficiently either.
Before giving all the technical definitions, let us say a bit about what the general classes look like at an intuitive level.
Class P: This is the set of all decision problems that can be solved in polynomial time. We will generally refer to these problems as being “easy” or “efficiently solvable”.
Class NP: This is the set of all decision problems that can be verified in polynomial time. This class contains P as a subset. It also contains a number of problems that are believed to be very “hard” to solve.
Class NP: The term “NP” does not mean “not polynomial”. Originally, the term meant “non-deterministic polynomial” but it is a bit more intuitive to explain the concept from the perspective of verification.
Class NP-hard: In spite of its name, to say that a problem is NP-hard does not mean that it is hard to solve. Rather, it means that if we could solve this problem in polynomial time, then we could solve all NP problems in polynomial time. Note that for a problem to NP-hard, it does not have to be in the class NP.
Class NP-complete: A problem is NP-complete if (1) it is in NP and (2) it is NP-hard.
The Figure 9.1 illustrates one way that the sets P, NP, NP-hard, and NP-complete (NPC) might look. We say might because we do not know whether all of these complexity classes are distinct or whether they are all solvable in polynomial time. The Graph Isomorphism, which asks whether two graphs are identical up to a renaming of their vertices. It is known that this problem is in NP, but it is not known to be in P. The other is QBF, which stands for Quantified Boolean Formulas. In this problem you are given a Boolean formula and you want to know whether the formula is true or false.
Figure 9.1: Complexity Classes
Quantified Boolean Formulas No Hamiltonian cycle
0/1 knapsack Hamiltonian cycle Satisfiability
Graph Isomorphism
Strong connectivity
The class NP is a set of all problems that can be verified by a polynomial time algorithm. Why the set is called “NP” and not “VP”? The original term NP stood for non-deterministic polynomial time. This referred to a program running on a non-deterministic computer that can make guesses. Such a computer could non-deterministically guess the value of the certificate and then verify it in polynomial time. We have avoided introducing non-determinism here; it is covered in other courses such as automata or complexity theory. Observe that P ⊆ N P. In other words, if we can solve a problem in polynomial time, we can certainly verify the solution in polynomial time. More formally, we do not need to see a certificate to solve the problem; we can solve it in polynomial time anyway. However, it is not known whether P= N P. It seems unreasonable to think that this should be so. Being able to verify that you have a correct solution does not help you in finding the actual solution. The belief is that P≠ N P but no one has a proof for this.
The class NP-complete (NPC) problems consist of a set of decision problems (a subset of class NP) that no one knows how to solve efficiently. But if there were a polynomial solution for even a single NP-complete problem, then ever problem in NPC will be solvable in polynomial time. For this, we need the concept of reductions.
Consider the question: Suppose there are two problems, A and B. You know (or you strongly believe at least) that it is impossible to solve problem A in polynomial time. You want to prove that B cannot be solved in polynomial time. We want to show that
(A ∉ P) ⇒ (B ∉ P)
How would you do this? Consider an example to illustrate reduction: The following problem is well-known to be NPC:
3-color: Given a graph G, can each of its vertices be labelled with one of 3 different colors such that two adjacent vertices have the same label (color).
Coloring arises in various partitioning problems where there is a constraint that two objects cannot be assigned to the same set of partitions. The term “coloring” comes from the original application which was in map drawing. Two countries that share a common border should be colored with different colors.
It is well known that planar graphs can be colored (maps) with four colors. There exists a polynomial time algorithm for this. But determining whether this can be done with 3 colors is hard and there is no polynomial time algorithm for it. In Figure 9.3, the graph on the left can be colored with 3 colors while the graph on the right cannot be colored.
Figure 9.3: Examples of 3-colorable and non-3-colorable graphs
Example1: Fish tank problem
Consider the following problem than can be solved with the graph coloring approach. A tropical fish hobbyist has six different types of fish designated by A, B, C, D, E, and F, respectively. Because of predator-prey relationships, water conditions and size, some fish can be kept in the same tank. The following table shows which fish cannot be together:
Type Cannot be with A B, C B A ,C, E C A,B,D,E D C, F E B, C, F F D, E
These constraints can be displayed as a graph where an edge between two vertices exists if the two species cannot be together. This is shown in Figure 9.4. For example, A cannot be with B and C; there is an edge between A and B and between A and C.
Given these constraints, What is the smallest number of tanks needed to keep all the fish? The answer can be found by coloring the vertices in the graph such that no two adjacent vertices have the same color. This particular graph is 3-colorable and therefore, 3 fish tanks are enough. This is depicted in Figure 9.5. The 3 fish tanks will hold fish as follows:
Tank 1 Tank 2 Tank 3
A,D F,C B,E
Suppose that you want to solve the CCov problem. But after a while of fruitless effort, you still cannot find a polynomial time algorithm for the CCov problem. How can you prove that CCov is likely to not have a polynomial time solution?
You know that 3Col is NP-complete and hence, experts believe that 3Col 26 P. You feel that there is some connection between the CCov problem and the 3Col problem. Thus, you want to show that
(3Col ∉ P) ⇒ (CCov ∉ P)
Both problems involve partitioning the vertices into groups. In the clique cover problem, for two vertices to be in the same group, they must be adjacent to each other. In the 3-coloring problem, for two vertices to be in the same color group, they must not be adjacent. In some sense, the problems are almost the same but the adjacency requirements are exactly reversed.
We claim that we can reduce the 3-coloring problem into the clique cover problem as follows: Given a graph G for which we want to determine its 3-colorability, output the pair (G, 3) where G denotes the complement of G. Feed the pair ( G, 3) into a routine for clique cover.
For example, the graph G in Figure 9.7 is 3-colorable and its complement (G, 3) is coverable by 3 cliques. The graph G in Figure 9.8 is not 3-colorable; it is also not coverable by cliques.
Figure 9.7: 3-colorable G and clique coverable ( G, 3)
G G
3-Colorable Coverable by 3 cliques
H H
Figure 9.8: G is not 3-colorable and (G, 3) is not clique coverable
9.6 Polynomial Time Reduction Definition: We say that a decision problem L 1 is polynomial-time reducible to decision problem L 2 (written L 1 ≤p L 2 ) if there is polynomial time computable function f such that for all x, x ∈ L 1 if and only if f(x) ∈ L 2.
In the previous example we showed that
In particular, we have f( G) = ( G, 3). It is easy to complement a graph in O(n^2 ) (i.e., polynomial time). For example, flip the 0’s and 1’s in the adjacency matrix.
The way this is used in NP-completeness is that we have strong evidence that L 1 is not solvable in polynomial time. Hence, the reduction is effectively equivalent to saying that “since L 1 is not likely to be solvable in polynomial time, then L 2 is also not likely to be solvable in polynomial time.
9.7 NP-Completeness
The set of NP-complete problems is all problems in the complexity class NP for which it is known that if any one is solvable in polynomial time, then they all are. Conversely, if any one is not solvable in polynomial time, then none are.
Definition: A decision problem L is NP-Hard if
L′ ≤P L for all L′ ∈ NP.
Definition: L is NP-complete if
Given this formal definition, the complexity classes are:
P: is the set of decision problems that are solvable in polynomial time.
NP: is the set of decision problems that can be verified in polynomial time.
NP-Hard: L is NP-hard if for all L ′ ∈ NP, L ′ ≤P L. Thus if we could solve L in polynomial time, we could solve all NP problems in polynomial time.
NP-Complete L is NP-complete if
Figure 9.9: Logical circuit for a boolean formula
Cook’s Theorem: SAT is NP-complete
We will not prove the theorem; it is quite complicated. In fact, it turns out that a even more restricted version of the satisfiability problem is NP-complete.
A literal is a variable x or its negation x. A boolean formula is in 3-Conjunctive Normal Form (3-CNF) if it is the boolean-and of clauses where each clause is the boolean-or of exactly three literals. For example,
(x 1 ∨ x 2 ∨ x 3 ) ∧ (x 1 ∨ x 3 ∨ x 4 ) ∧ (x 2 ∨ x 3 ∨ x 4 )
is in 3-CNF form. 3SAT is the problem of determining whether a formula is 3-CNF is satisfiable. 3SAT is NP-complete. We can use this fact to prove that other problems are NP-complete. We will do this with the independent set problem. Independent Set Problem: Given an undirected graph G=(V, E) and an integer k, does G contain a subset V′ of k vertices such that no two vertices in V′ are adjacent to each other.
Figure 9.10:
The independent set problem arises when there is some sort of selection problem where there are mutual restrictions pairs that cannot both be selected. For example, a company dinner where an employee and his or her immediate supervisor cannot both be invited.
Claim: IS is NP-complete The proof involves two parts. First, we need to show that IS ∈ NP. The certificate consists of k vertices of V′. We simply verify that for each pair of vertices u, v 2 V′, there is no edge between them. Clearly, this can be done in polynomial time, by an inspection of the adjacency matrix. Second, we need to establish that IS is NP-hard This can be done by showing that some known NP-compete (3SAT) is polynomial-time reducible to IS. That is, 3SAT ≤P IS.
An important aspect to reductions is that we do not attempt to solve the satisfiability problem. Remember: It is NP-complete, and there is not likely to be any polynomial time solution. The idea is to translate the similar elements of the satisfiable problem to corresponding elements of the independent set problem.
What is to be selected?
3SAT: Which variables are to be assigned the value true, or equivalently, which literals will be true and which will be false.
IS: Which vertices will be placed in V′.
Requirements:
3SAT: Each clause must contain at least one true valued literal.
IS: V′ must contain at least k vertices.
Restrictions:
3SAT: If x i is assigned true, then x i must be false and vice versa.
IS: If u is selected to be in V′ and v is a neighbor of u then v cannot be in V′. We want a function which given any 3-CNF boolean formula F, converts it into a pair ( G, k) such that the above elements are translated properly. Our strategy will be to turn each literal into a vertex. The vertices will be in clause clusters of three, one for each clause. Selecting a true literal from some clause
Figure 9.12: Each term is connected to its complement
The boolean formula is satisfied by the assignment x 1 = 1, x 2 = 1 x 3 = 0. This implies that the first literal of the first and last clauses are 1, the second literal of the second clause is 1, and the third literal of the third clause is 1. By selecting vertices corresponding to true literals in each clause, we get an independent set of size k= 4. This is shown in Figure 9.13.
Figure 9.13: Independent set corresponding to x 1 = 1, x 2 = 1 x 3 = 0
Correctness Proof: We claim that F is satisfiable if and only if G has an independent set of size k. If F is satisfiable, then each of the k clauses of F must have at least one true literal. Let V ′ denote the corresponding vertices from each of the clause clusters (one from each cluster). Because we take vertices from each cluster, there are no inter-cluster edges between them, and because we cannot set a variable and its complement to both be true, there can be no edge of the form (xi , xi ) between the vertices of V ′. Thus, V ′ is an independent set of size k. Conversely, G has an independent set V ′ of size k. First observe that we must select a vertex from each clause cluster, because there are k clusters, and we cannot take two vertices from the same cluster (because they are all interconnected). Consider the assignment in which we set all of these literals to 1. This
assignment is logically consistent, because we cannot have two vertices labelled xi and xi in the same cluster.
Finally the transformation clearly runs in polynomial time. This completes the NP-completeness proof.
Also observe that the the reduction had no knowledge of the solution to either problem. Computing the solution to either will require exponential time. Instead, the reduction simple translated the input from one problem into an equivalent input to the other problem.
With NP-completeness we have seen that there are many important optimization problems that are likely to be quite hard to solve exactly. Since these are important problems, we cannot simply give up at this point, since people do need solutions to these problems. Here are some strategies that are used to cope with NP- completeness:
Use brute-force search: Even on the fastest parallel computers this approach is viable only for the smallest instance of these problems.
Heuristics: A heuristic is a strategy for producing a valid solution but there are no guarantees how close it to optimal. This is worthwhile if all else fails.
General search methods: Powerful techniques for solving general combinatorial optimization problems. Branch-and-bound, A*-search, simulated annealing, and genetic algorithms
Approximation algorithm: This is an algorithm that runs in polynomial time (ideally) and produces a solution that is within a guaranteed factor of the optimal solution.