NP-completeness and the classes P and NP
Classes P
The class P consists of those problems that are solvable in polynomial time.
More specifically, they are problems that can be solved in time
constant k, where n is the size of the input to the problem.
Classes NP
The class NP consists of those problems that are “verifiable” in polynomial time.
What do we mean by a problem being verifiable? If we were somehow given a
“certificate” of a solution, then we could verify that the certificate is correct in time
polynomial in the size of the input to the problem.
NP-completeness
Informally, a problem is in the class NPC—and we refer to it as being NP-complete if
it is in NP and is as “hard” as any problem in NP.
In the meantime, we will state without proof that if any NP-complete problem
can be solved in polynomial time, then every problem in NP has a polynomialtime
algorithm.
Reference:
Polynomial time
Abstract problems
To understand the class of polynomial-time solvable problems, we must first have
a formal notion of what a “problem” is. We define an abstract problem Q to be a
binary relation on a set I of problem instances and a set S of problem solutions.
For example, an instance for SHORTEST-PATH is a triple consisting of a graph
and two vertices. A solution is a sequence of vertices in the graph, with perhaps
the empty sequence denoting that no path exists. The problem SHORTEST-PATH
itself is the relation that associates each instance of a graph and two vertices with
a shortest path in the graph that connects the two vertices. Since shortest paths are
not necessarily unique, a given problem instance may have more than one solution.
Endocing
In order for a computer program to solve an abstract problem, we must represent
problem instances in a way that the program understands. An encoding of a set S
of abstract objects is a mapping e from S to the set of binary strings.
A formal-language framework
Omit!
Exercise
Show that if an algorithm makes at most a constant number of calls to polynomial-time subroutines and performs an additional amount of work that also takes polynomial time, then it runs in polynomial time. Also show that a polynomial number of calls to polynomial-time subroutines may result in an exponential-time algorithm.
Polynomial-time verification
Hamiltonian cycles
A hamiltonian cycle of an undirected graph
We can define the hamiltonian-cycle problem, “Does a graph G have a hamiltonian cycle?” as a formal language:
This naive algorithm does not run in polynomial time. In fact, the hamiltonian-cycle problem is NP-complete.
Verification algorithms
We define a verification algorithm as being a two-argument algorithm A, where one argument is an ordinary input string x and the other is a binary string y called a certificate. A two-argument algorithm A verifies an input string x if there exists a certificate y such that
The complexity class NP
Omit!
Exercises
Question 1
Prove that if
Answer
Let graph G be a bipartite graph with an odd number of vertices and G be Hamiltonian, meaning that there is a directed cycle that includes every vertex of G. As such, there exists a cycle in G would of odd length. However, a graph G is bipartite if and only if every cycle of G has even length. Proven by contradiction, if G is a bipartite graph with an odd number of vertices, then G is non-Hamiltonian.
Question 2
Show that any language in NP can be decided by an algorithm running in time
Answer
Question 3
A hamiltonian path in a graph is a simple path that visits every vertex exactly
once. Show that the language
Answer
Question 4
Show that the hamiltonian-path problem from Exercise 34.2-6 can be solved in polynomial time on directed acyclic graphs. Give an efficient algorithm for the problem.
Answer
For this particular problem, we could find a polynomial-time solution for it and then it’s proven it could be solved in polynomial-time.
In this following step, I will give some steps that will demonstrate it will resolve the problem:
1) find a path in the original graph
2) remove the source node which in-degree is zero and its neighboring edges so that we could find the next node to start, let’s assume that the left graph is
3) if the left graph
4) keep doing the 3) until we have reached the end-point, which there is no other nodes to visit. If there is some nodes that are not visited but we cannot find an edge to reach it, then it’s unsolvable, otherwise we should get the solution.
From the above steps, we have found the solution for the hamiltonian-path, and its complexity if
NP-completeness and reducibility
Reducibility
A language
If there exists a polynomial-time computable function $f :{0, 1}^ \rightarrow {0, 1}^
We call the function f the reduction function, and a polynomial-time algorithm F that computes f is a reduction algorithm.
NP-completeness
A language
, and for every .
If a language L satisfies property 2, but not necessarily property 1, we say that L is NP-hard. We also define NPC to be the class of NP-complete languages.
Circuit satisfiability
The language CIRCUIT-SAT is therefore at least as hard as any language in NP, and since it belongs to NP, it is NP-complete.
Exercise
Question 1
Show that the
Answer
Question 2
A language L is complete for a language class C with respect to polynomial-time reductions if
Answer
Omit
NP-completeness proofs
Language L is NP-complete:
- Prove
. - Select a known NP-complete language
. - Describe an algorithm that computes a function
mapping every instance of to an instance of . - Prove that the function
satisfies if and only if for all . - Prove that the algorithm computing
runs in polynomial time.
3-CNF satisfiability
We define 3-CNF satisfiability using the following terms. A literal in a boolean formula is an occurrence of a variable or its negation. A boolean formula is in conjunctive normal form, or CNF, if it is expressed as an AND of clauses, each of which is the OR of one or more literals. A boolean formula is in 3-conjunctive normal form, or 3-CNF, if each clause has exactly three distinct literals.
Theorem
Satisfiability of boolean formulas in 3-conjunctive normal form is NP-complete.
Exercises
Question 1
Consider the straightforward (nonpolynomial-time) reduction in the proof of Theorem 34.9. Describe a circuit of size n that, when converted to a formula by this method, yields a formula whose size is exponential in n.
Answer
Question 2
Suppose that someone gives you a polynomial-time algorithm to decide formula satisfiability. Describe how to use this algorithm to find satisfying assignments in polynomial time.
Answer
NP-complete problems
What the F*!
Exercises
Question 1
The subgraph-isomorphism problem takes two undirected graphs
v1.5.2