CS600

Informal Characterization of Class NP



Characterizations

Class NP can be characterized in a number of different but equivalent ways.

1. Non-deterministic Polynomial

NP is the class of decision problems that can be solved by a non-deterministic algorithm in time bounded by a polynomial in the size of the problem.

Informally, a non-deterministic algorithm is a fictitious algorithm which finds an yes answer in polynomial time by making arbitrary choices among a finite number of alternatives such as deciding to take or not to take an object with you on a trip; deciding to pair one member with another or not; assigning a course to a certain time slot or not and so on.

Note that to be able to do that it would have to verify its (candidate) answer in polynomial time.

If a problem can be solved by making such non-deterministic decisions a polynomial number of times then it is in class NP.

2. Backtrack of Polynomial Depth

NP is the class of decision problems that can be solved by an algorithm which finds a solution by making choices from a finite number of alternatives with possible backtrackings of depth bounded by a polynomial in the size of the problem.

3. Verifiability

NP is the class of decision problems that have a certificate of length bounded by a polynomial in the size of the problem, and whose certificate can be verified in time bounded by a polynomial in the size of the problem.
A certificate for a decision problem is an evidence that supports the yes answer if the answer to the instance is yes. See below for an example.

Examples

Let us consider the graph coloring problem. An instance of this problem is an undirected graph G and a positive integer k, and the question is whether or not the vertices of G can be colored with k or less colors in such a way that every vertex receives exactly one color and that no adjacent vertices receive the same color.

1. Characterization by Non-deterministic Algorithm:

A non-deterministic algorithm (look at this algorithm as a very smart person) selects one of the k colors for the vertices of G one vertex at a time but it always makes the right selection. All it has to do is to make a selection n times if G has n vertices. So the time it needs is bounded by a polynomial in n, the size of the problem, and the selections it makes always lead to a correct coloring of vertices.
Thus the graph coloring problem is in class NP.

It is as if a very smart person is finding a correct solution by inspection. Such an algorithm certainly does not exist in reality. But it captures the nature of the class NP.

2. Characterization by Backtrack Algorithm:

A naive backtrack algorithm could assign one of the k colors to each of the vertices one vertex at a time in some order so that no two adjacent vertices receive the same color.

In general, more than k colors become necessary at some point. Then backtrack to the first vertex (call it v) with some untried colors, removing the color from every vertex on the way as well as from v. If there are some untried colors exist for v, assign one of the untried colors to v and continue coloring the remaining vertices in the same manner until either all vertices are colored, or a backtrack become necessary.
If v is the vertex the algorithm was started with and if all k colors have been tried for v, then the given graph G can not be colored with k or less colors.

This algorithm certainly finds a coloring if one exists. Since you backtrack on vertices, and there are n vertices, the depth of backtrack is at most n, the size of the problem.
Thus the graph coloring problem is in class NP by this criterion.

Note that in the worst case this takes O(kn) time. In general, if the number of alternatives at each backtrack is at most k, and the depth of backtrack is p(n) for some polynomial p, then the worst case computation time is O(kp(n)).

Also note that if we try all possible assignments of k colors to n vertices one by one until a desired assignment is found, it is also a backtrack algorithm. However, the depth of backtrack is not bounded by a polynomial in n, because in the worst case tex2html_wrap_inline90 assignments must be examined thus that many backtracks are necessary.

3. Characterization by Verification:

The decision problem version of the graph coloring problem asks "Can the vertices of the given graph be colored with k or less colors ?". The answer to this question is yes or no. Suppose that the answer to an instance of this problem is yes. Then we would like to know why the answer is yes. An evidence to support this answer is a certificate. For example, an assignment of k or less colors to the vertices is a certificate. It is a list of vertices and their colors. Hence its length is certainly of a polynomial in the input size. To verify that the certificate is a correct solution, a verification algorithm needs to check
1) every vertex is colored with one color
2) the number of colors used is k or less, and
3) no adjacent vertices have the same color.

Of these 1) and 2) can be checked by going through the list (certificate) once. This takes O(n) time. 3) can be checked by examining every pair of vertices to see that they have different colors. This takes tex2html_wrap_inline96 time. Hence the certificate can be verified in time bounded by a polynomial in the size of the problem. Hence the graph coloring problem is in class NP.

Note that a proof that the answer is yes is also a certificate. However, it would not be easy to verify the proof.