90 likes | 116 Views
NP-Completeness (36.4-5/34.4-5). P: yes and no in pt NP: yes in pt NPH NPC. NP-hard. NPC. P. NP. Satisfiability. Boolean formulas: x, (x y) (x y) (xy) (xy) Satisfiability Problem (SP): given a Boolean formula
E N D
NP-Completeness (36.4-5/34.4-5) • P: yes and no in pt • NP: yes in pt • NPH NPC NP-hard NPC P NP
Satisfiability • Boolean formulas: x, (x y) (x y) (xy) (xy) • Satisfiability Problem (SP): • given a Boolean formula • is there any 0-1 input (0-1 assignment to variables) s.t. formula is true (=1)? • Cook’s Theorem: SP is NP-complete. • SP is an NP-problem (why?) • SP is NP-hard (w/o proof)
3-CNF • Conjunctive normal form (CNF) = (l11 l12 ... l1s1) ... (ln1 ln2 ... lnsn) • each literal l is either variable or negation • 3-CNF: each si=3 • 3-CNF Satisfiability is NPC (x1 x2) (x1 x4 ) • Corresponding tree y3(y1 (x1 x2)) (y2 ( x1 x4 )) • Truth assignment for each clause using tables. y3 y1 y2 x1 x2 x1 x4
x x’ a’ z z’ x y’ a y Independent Set • Independent set in a graph G: pairwise nonadjacent vertices • Max Independent Set is NPC • Is there independent set of size k? • Construct a graph G: • literal -> vertex • two vertices are adjacent iff • they are in the same clause • they are negations of each other • 3-CNF with k clauses is satisfiable iff G has independent k-set • assign 1’s to literals-vertices of independent set • Example: f = (x+z+y’) & (x’+z’+a) & (a’+x+y) x, z’, y independent F is satisfiable: f = 1 if x = z’ = y = 1
red independent set MAX Clique • Max Clique (MC): • Find the maximum number of pairwise adjacent vertices • MC is in NP • for the answer yes there is certificate of polynomial length = clique which can be checked in polynomial time • MC is in NPC • Polynomial time reduction from MIS: • For any graph G any independent set in G 1-1 corresponds to clique in the complement graph G’ red clique noedge edge edge noedge G Complement G’
Minimum Vertex Cover • Vertex Cover: • the set of vertices which has at least one endpoint in each edge • Minimum Vertex Cover (MVC): • the set of vertices which has at least one endpoint in each edge • MIN Vertex Cover is NPC • If C is vertex cover, then V - C is an independent set red independent set blue vertex cover
Set Cover • Given: a set X and a family F of subsets of X, F 2X, s.t. X covered by F • Find : subfamily G of F such that G covers X and |G| is minimize • Set Cover is NPC • reduction from Vertex Covert • Graph representation: edge between set A F and element x X means x A d a b c red elements of ground set X blue subsets in family F A B A = {a,b,c}, B = {c,d}
NP-hard NPC P NP Intermediate Classes Dense Set Cover is NP but not in P neither in NPC Dense Set Cover: Each element of X belongs to at least half of all sets in F
2 . . . 2 2 n times Runtime Complexity Classes • Example • adding an element in a queue/stack • inverse Ackerman function = O(loglog…log n) n times • extracting minimum from binary heap • n1/2 • traversing binary search tree, list • O(n log n) sorting n numbers, closest pair, MST, Dijkstra shortest paths • adding two nn matrices • en ^ (1/2) • en, , n! • Ackerman function • Runtime order: • constant • almost constant • logarithmic • sublinear • linear • pseudolinear • quadratic • polynomial • subexponential • exponential • superexponential