Docsity

Computational Complexity - Lecture Slides | CIS 511, Study notes of Computer Science

Partial preview of the text

Download Computational Complexity - Lecture Slides | CIS 511 and more Study notes Computer Science in PDF only on Docsity!

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 439 of 488 Go Back Full Screen Close

Chapter 7

Computational Complexity

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 440 of 488 Go Back Full Screen Close

7.1. The Class P

In the previous two chapters, we clarified what it means for a problem to be decidable or undecidable.

In principle, if a problem is decidable, then there is an algo- rithm (i.e., a procedure that halts for every input) that decides every instance of the problem.

However, from a practical point of view, knowing that a prob- lem is decidable may be useless, if the number of steps (time complexity) required by the algorithm is excessive, for exam- ple, exponential in the size of the input, or worse.

For instance, consider the traveling salesman problem, which can be formulated as follows:

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 442 of 488 Go Back Full Screen Close Quit

Thus, to capture the essence of practically feasible algorithms, we must limit our computational devices to run only for a number of steps that is bounded by a polynomial in the length of the input.

We are led to the definition of polynomially bounded compu- tational models.

Definition 7.1.1 A deterministic Turing machine M is said to be polynomially bounded if there is a polynomial p(X) so that the following holds: For every input x ∈ Σ∗, there is no ID IDn so that

ID 0 `∗^ IDn, with n > p(|x|),

where ID 0 = q 0 x is the starting ID.

A language L ⊆ Σ∗^ is polynomially decidable if there is a polynomially bounded Turing machine that accepts L. The family of all polynomially decidable languages is denoted by P.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 443 of 488 Go Back Full Screen Close

Remark: Even though Definition 7.1.1 is formulated for Tur- ing machines, it can also be formulated for other models, such as RAM programs.

The reason is that the conversion of a Turing machine into a RAM program (and vice versa) produces a program (or a machine) whose size is polynomial in the original device.

The following lemma, although trivial, is useful:

Lemma 7.1.2 The class P is closed under complementation.

Of course, many languages do not belong to P. One way to obtain such languages is to use a diagonal argument. But there are also many natural languages that are not in P, although this may be very hard to prove for some of these languages.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 445 of 488 Go Back Full Screen Close

Definition 7.2.1 Given a graph G, an Eulerian cycle is a cycle in G that passes through all the nodes (possibly more than once) and every edge of G exactly once. A Hamiltonian cycle is a cycle that passes through all the nodes exactly once (note, some edges may not be traversed at all).

Eulerian Cycle Problem: Given a graph G, is there an Eulerian cycle in G?

Hamiltonian Cycle Problem: Given a graph G, is there an Hamiltonian cycle in G?

It may come as a surprise that the Eulerian Cycle Problem does have a polynomial time algorithm, but that so far, not such algorithm is known for the Hamiltonian Cycle Problem.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 446 of 488 Go Back Full Screen Close

The reason why the Eulerian Cycle Problem is decidable in polynomial time is the following theorem due to Euler:

Theorem 7.2.2 A graph G = (V, E) has an Eulerian cycle iff the following properties hold:

(1) The graph G is strongly connected. (2) Every node has the same number of incoming and outgo- ing edges.

Proving that properties (1) and (2) hold if G has an Eulerian cycle is fairly easy. The converse is harder, but not that bad (try!).

Theorem 7.2.2 shows that it is necessary to check whether a graph is strongly connected. This can be done by computing the transitive closure of E, which can be done in polynomial time (in fact, O(n^3 )).

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 448 of 488 Go Back Full Screen Close

7.3. Propositional Logic and Satisfiability

We define the syntax and the semantics of propositions in conjunctive normal form (CNF).

The syntax has to do with the legal form of propositions in CNF. Such propositions are interpreted as truth functions, by assigning truth values to their variables.

We begin by defining propositions in CNF. Such propositions are constructed from a countable set, PV, of propositional (or boolean) variables, say

PV = {x 1 , x 2 ,... , },

using the connectives ∧ (and), ∨ (or) and ¬ (negation).

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 449 of 488 Go Back Full Screen Close

We define a literal (or atomic proposition), L, as L = x or L = ¬x, also denoted by x, where x ∈ PV.

A clause, C, is a disjunction of pairwise distinct literals,

C = (L 1 ∨ L 2 ∨ · · · ∨ Lm).

Thus, a clause may also be viewed as a nonempty set

C = {L 1 , L 2 ,... , Lm}.

We also have a special clause, the empty clause, denoted ⊥ or (or {}). It corresponds to the truth value false. A proposition in CNF, or boolean formula, P , is a conjunc- tion of pairwise distinct clauses

P = C 1 ∧ C 2 ∧ · · · ∧ Cn.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 451 of 488 Go Back Full Screen Close

A truth assignment (or valuation), v, is any function v: PV → BOOL.

Given a truth assignment, v: PV → BOOL, we define the truth value, ̂v(X), of a literal, clause, and boolean formula, X, using the following recursive definition:

(1) ̂v(⊥) = F, ̂v(>) = T. (2) ̂v(x) = v(x), if x ∈ PV.

(3) ̂v(x) = v(x), if x ∈ PV, where v(x) = F if v(x) = T and v(x) = T if v(x) = F.

(4) ̂v(C) = F if C is a clause and iff ̂v(Li) = F for all literals Li in C, otherwise T.

(5) ̂v(P ) = T if P is a boolean formula and iff ̂v(Cj ) = T for all clauses Cj in P , otherwise F.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 452 of 488 Go Back Full Screen Close

Definition 7.3.1 We say that a truth assignment, v, satisfies a boolean formula, P , if ̂v(P ) = T. In this case, we also write

v |= P.

A boolean formula, P , is satisfiable if v |= P for some truth assignment v, otherwise, it is unsatisfiable. A boolean formula, P , is valid (or a tautology) if v |= P for all truth assignments v, in which case we write

|= P.

One should check that the boolean formula

P = {(x 1 ∨ x 2 ∨ x 3 ), (x 1 ∨ x 2 ), (x 2 ∨ x 3 ), (x 3 ∨ x 1 ), (x 1 ∨ x 2 ∨ x 3 )}

is unsatisfiable.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 454 of 488 Go Back Full Screen Close

The first step consists in observing that if every clause in P contains at most two literals, then we can reduce the prob- lem to testing satisfiability when every clause has exactly two literals.

Indeed, if P contains some clause (x), then any valuation sat- isfying P must make x true. Then, all clauses containing x will be true, and we can delete them, whereas we can delete x from every clause containing it, since x is false.

Similarly, if P contains some clause (x), then any valuation satisfying P must make x false.

Thus, in a finite number of steps, either we get the empty clause, and P is unsatisfiable, or we get a set of clauses with exactly two literals.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 455 of 488 Go Back Full Screen Close Quit

The number of steps is clearly linear in the number of literals in P.

For the second step, we construct a directed graph from P. The nodes of this graph are the literals in P , and edges are defined as follows:

(1) For every clause (x ∨ y), there is an edge from x to y and an edge from y to x.

(2) For every clause (x ∨ y), there is an edge from x to y and an edge from y to x

(3) For every clause (x ∨ y), there is an edge from x to y and an edge from y to x.

Then, it can be shown that P is unsatisfiable iff there is some x so that there is a cycle containing x and x.

As a consequence, 2-satisfiability is in P.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 457 of 488 Go Back Full Screen Close

Definition 7.4.1 A nondeterministic Turing machine M is said to be polynomially bounded if there is a polynomial p(X) so that the following holds: For every input x ∈ Σ∗, there is no ID IDn so that

ID 0 `∗^ IDn, with n > p(|x|),

where ID 0 = q 0 x is the starting ID.

A language L ⊆ Σ∗^ is nondeterministic polynomially decidable if there is a polynomially bounded nondeterministic Turing machine that accepts L. The family of all nondeterministic polynomially decidable languages is denoted by N P.

More Problems Propositional Logic... The Class N P,... Cook’s Theorem

Home Page Title Page JJ II J I Page 458 of 488 Go Back Full Screen Close

Of course, we have the inclusion

P ⊆ N P,

but whether or not we have equality is one of the most famous open problems of theoretical computer science and mathemat- ics.

In fact, the question P 6 = N P is one of the open problems listed by the CLAY Institute, together with the Poincar´e con- jecture and the Riemann hypothesis, among other problems, and for which one million dollar is offered as a reward!

It is easy to check that SAT is in N P, and so is the Hamilto- nian cycle problem.