§4 Computational Complexity Model of computation with (bit) cost: WHILE+ Complexity of Arithmetic Complexity classes P, NP, PSPACE, EXP and their inclusion relations Encoding graphs/non-integer data Example problems: 3COL, EC, HC, VC, ILP, IS, Clique
Model of Computational Cost WHILE takes expon. time to add two n-bit integers Now WHILE+ programs: Input x1N, output x0N xj := 0 | xj := 1 | xj := xi + xk | xj := xi xk | xj := xi 2 | guess xj | P;P | WHILE xi DO P END Definitions: binary length of xN: ℓ(x) = log2(1+x) time of a WHILE+ program P on input x=(x1,…xk) space (=memory) used: maxt ℓ(x):=ℓ(x1)+…+ℓ(xk) asymptotic time/space t(n)/s(n): worst-case over all inputs x with ℓ(x)<n Recall pairing function x,y := x + (x+y)·(x+y+1)/2
Complexity of Arithmetic WHILE takes expon. time to add two n-bit integers Now WHILE+ programs: Input x1N, output x0N xj := 0 | xj := 1 | xj := xi + xk | xj := xi xk | xj := xi 2 | guess xj | P;P | WHILE xi DO P END Multiplication by repeated addition: expon. time Long multiplication: linear time Long division: linear time Un-/pairing: linear time ℓ(x,y) = ( ℓ(x) + ℓ(y) ) ℓ(x) = (log x) asymptotic time/space t(n)/s(n): worst-case over all inputs x with ℓ(x)<n Recall pairing function x,y := x + (x+y)·(x+y+1)/2
Preliminaries: Graphs and Coding A directed graph G=(V,E) is a finite set V of vertices and a set EVV of edges Call G undirected if it holds (u,v)E (v,u)E sometimes c:E→N assigning weights to edges. For input to a WHILE+ program: Represent (G,c) as adjacency matrix ANVV A[u,v] := c(i,j) for (u,v) E, A[u,v] := "∞" for (u,v) E Undirected case: only upper triangular matrix. Encoding G,cN has |V| ≤ |G,c| ≤ O(|V|²·log |c|∞)
Some Complexity Classes Definition: a) An ‘algorithm‘ computes the function f:NN if on input x it prints f(x) and terminates A WHILE+ program in time t(n) / space s(n), n:=ℓ(x) Polynom.growth: k t(n)≤O(nk); exponential: 2O(nk) Def: For decision problems L N or L {0,1}* Definitions: binary length of xN: ℓ(x) = log2(1+x) time of a WHILE+ program P on input x=(x1,…xk) space (=memory) used: maxt ℓ(x):=ℓ(x1)+…+ℓ(xk) asymptotic time/space t(n)/s(n): worst-case over all inputs x with ℓ(x)<n better pairing function x,y := x + (x+y)·(x+y+1)/2 P = { L decidable in polynomial time } NP = { L verifiable in polynomial time }, i.e. L = { xN : yN, ℓ(y)≤poly(ℓ(x)), x,yV }, VP PSPACE = { L decidable in polynomial space } EXP = { L decidable in exponential time } Theorem: P NP PSPACE EXP L = { xN : yN, ℓ(y)≤poly(ℓ(x)), x,yV }, VP
NP {xN: y, ℓ(y)≤poly(ℓ(x)), x,yV }, VP Example Problem (0) Def: A 3-coloring of G=(V,E) is a mapping γ:V→{R,G,B} s.t. γ(u)≠γ(v) for every (u,v)E. Examples: a) The Petersen Graph admits a 3-coloring. b) This graph, too. c) This one still. d) But not this one. x = G, y = γ(1),… γ(|V|) 3COL= { G | G admits a 3-coloring } NP NP {xN: y, ℓ(y)≤poly(ℓ(x)), x,yV }, VP
Example Problems (I) NP NP EC := { G | G has a Eulerian cycle} In an undirected graph G, Eulerian cycle traverses each edge precisely once; Hamiltonian cycle visits each vertex precisely once. save isolated vertices G admitting a Eulerian cycle is connected and has an even number of edges incident to each vertex Theorem: Conversely every connected graph with an even number of edges incident to each vertex admits a Eulerian cycle. EC := { G | G has a Eulerian cycle} NP NP {xN: y, ℓ(y)≤poly(ℓ(x)), x,yV }, VP HC := { G | G has Hamiltonian cycle} NP
Example Problems (II) NP NP NP NP ? Eulerian (EC) vs. Hamiltonian Cycle (HC) (Minimum) Edge Cover "To graph G, find a smallest subset Fof edges s.t. any vertex v is adjacent to at least one eF." vs. Vertex Cover (VC) CLIQUE = { G,k | G contains a k-clique } IS={G,k : G has k pairwise non-adjacent vertices} Integer Linear Programming ILP = { A,b : AZnm, bZm, xZn: A·x = b } NP NP Greedily extend a maximum matching NP NP ? {V,E,k: FE, |F|=k, xV yV: (x,y)F } VC = {V,E,k: UV, |U|=k, (x,y)E: xU yU } NP {xN: y, ℓ(y)≤poly(ℓ(x)), x,yV }, VP
Example Problems (III) Def: A Boolean term Φ(Y1,…Yn) is composed from variables Y1,…Yn, constants 0 and 1, and operations , , . Examples: • 0 (x y ) ( x y ) (x y) (x y) y (x y) (x z ) (z y) x (y) clause literals Φ in 3-CNF if Φ = (()yi ()yj ()yℓ ) EVAL: Given Φ(Y1,…Yn) and y1,…yn{0,1}, does Φ(y1,…yn) evaluate to 1 ? [k-] SAT: Given Φ(Y1,…Yn) [in k-CNF], does it hold y1,…yn{0,1}: Φ(y1,…yn)=1 ? P
Non-Deterministic WHILE+ Theorem: LN is accepted by a non-deterministic polynomial-time WHILE+ program iff LNP. Now LOOP+ programs: Input x1N, output x0N xj := 0 | xj := 1 | xj := xi + xk | xj := xi xk | xj := xi 2 | guess xj | P;P | WHILE xi DO P END guess xj | Definition: A non-deterministic WHILE+ program may (repeatedly) guess a bit (0/1). Its runtime is ≤t(n) if it makes no more than t(ℓ(x1)) steps, regardless of the guesses. It accepts input x1 if there exists some choice of guessed values such as to return x0=1. It rejects x1 if no choice of guesses returns x0=1.