Checking solutions efficiently The class P : set of languages L f decidable in time O ( n c ). Function f can be computed in poly-time. The Class NP What if don’t know how to compute f in poly-time? Nabil Mustafa 3-CNF satisfiability. Not known how to find an assignment. Instead, settle for languages with efficiently verifiable Computability and Complexity solutions. Define a new class NP : A function f is in NP if There exists a poly-sized solution of f – say u Verify in polynomial time that u is a correct solution for f Nabil Mustafa The Class NP Nabil Mustafa The Class NP Defining NP Examples of Problem in NP INDSET : Given a graph G and a integer k , decide if G has an independent set (I.S.) of size k . NP Language L is in NP if for any x ∈ L , A language L is in NP if for any x ∈ { 0 , 1 } ∗ , ⇒ ∃ u ∈ { 0 , 1 } p ( | x | ) s . t . M ( x , u ) = 1 x ∈ L ⇐ ⇒ ∃ u ∈ { 0 , 1 } p ( | x | ) s . t . M ( x , u ) = 1 x ∈ L ⇐ where M is a poly-time TM and p ( | x | ) is a polynomial. Language L : set of all graphs with independent set of size k Input x : graph G and integer k Certificate u : V ′ ⊆ V , | V ′ | = k , and V ′ is an I.S. u called a certificate for x p ( | x | ): binary labels of k vertices, of total size k log n . Note that the implication goes both ways. M ( x , u ): TM M which verifies in polynomial time if u = V ′ is an independent set of size k Nabil Mustafa The Class NP Nabil Mustafa The Class NP
Some Examples Relation between P and NP Claim: 3-CNF satisfiability is in NP Claim If f is satisfiable = ⇒ ∃ a satisfying assignment u If L ∈ P , then L ∈ NP . In other words, P ⊆ NP The satisfying assignment u has polynomial size. Given f and u , can verify in O ( nm ) that u satisfies f Proof. Claim: k -coloring is in NP Suppose L ∈ P decided by polynomial-time TM M If G is k -colorable = ⇒ ∃ a correct coloring c Take the TM for NP as N = M The correct coloring c has polynomial size u is empty string = ⇒ N takes only x Given G and c , verify in O ( m ) time that c correctly colors G If x ∈ L : N will return 1 If x / ∈ L : N will return 0 Subset sum: Given n integers A 1 , . . . , A n and integer T , does there exist a subset of numbers that sum up to T Claim: Subset sum is in NP Nabil Mustafa The Class NP Nabil Mustafa The Class NP Relation between NP and DTIME Non-deterministic Turing Machines Claim Saw that a TM is defined by the tuple NP ⊆ DTIME (2 n c ) (Γ : symbols , Q : a set of states , δ : the transition function ) Proof. The transition function: δ : Q × Γ → Q × Γ × { L , R , S } If L ∈ NP , we know that a poly-time TM M exists s.t. NTM : Relax δ to instead just be a relation If x / ∈ L , no u will make M ( x , u ) = 1 if x ∈ L , ∃ a u such that M ( x , u ) = 1 This implies for the same ( q j , σ i ), many possible rules Now this M is a poly-time TM ( q j , σ i ) = ⇒ ( q j ′ , σ i ′ , L ) The problem is that M doesn’t know u or how to compute u Solution: Just enumerate all possible u ( q j , σ i ) = ⇒ ( q j ′′ , σ i ′′ , R ) If it works for some u , output 1, otherwise 0 This works because: Given an input x , the computation of a NTM is valid if a If x / ∈ L , enumeration never finds a u such that M ( x , u ) = 1 valid rule is applied at each time-step t if x ∈ L , will find the required u Instead of a computation ‘path’, we have computation ‘tree’ Total time for enumeration: O (2 p ( | x | ) ) = O (2 n c ) A node at depth t is the configuration of NTM at time t A = child ( B ) if there is a valid rule to go from B to A Nabil Mustafa The Class NP Nabil Mustafa The Class NP
Deciding Languages Non-deterministic Turing Machines NTM computes a function such that An accepting path in this computation tree is a set of At each computational step, M has to choose from a number transition rules that can be applied to go to an accepting state of rules all of which would be validly applied. Note: in TM , one path to follow, which accepts or rejects If there is some sequence of choices that end in the state q accept then M ( x ) = 1. In NTM , some paths might accept, others might reject If there is no sequence of choices that end in state q accept then NTM accepts x iff there exists an accepting path we define M ( x ) = 0. Not concerned with how the transition choices are made Definition of Time Complexity of a NTM The running time of a NTM on input x ∈ L is the length of shortest accepting path The running time of a NTM on input x / ∈ L is the length of shortest rejecting path If some path of NTM does not halt on input x , running time is undefined. Figure: 5 possible transition rules can be applied from the current state Nabil Mustafa The Class NP Nabil Mustafa The Class NP Different Computational paths in NTM NTM Example – Traveling Salesman Problem TSP : Given a matrix of distances between n cities, decide if there is a path visiting all cities with total distance at most k A NTM can find such a route as following: At each state, make a guess out of the available cities until it has visited every city. If get stuck, stop immediately with q reject At the end, verify that the route takes cost less than k . If no, enter q reject Otherwise, enter q accept Nabil Mustafa The Class NP Nabil Mustafa The Class NP
NTM Example - Traveling Salesman Problem NTM Example - Traveling Salesman Problem Only one input and one output tape. No work tape. States Q = { q start , city a , city b , city c , city d , city e , q halt } Symbols Γ = { a , b , c , d , e } Partial transition table for NTM is Shown Q IT Γ Q OT Γ q start a city a a q start b city b b q start c city c c city e d city d d city e c city c c city a b city b b city a d city d d city b e city e e Nabil Mustafa The Class NP Nabil Mustafa The Class NP Time Complexity Defining NP another way Running time Given: Definition A Non-Deterministic Turing machine NTM f : { 0 , 1 } ∗ → { 0 , 1 } � NTIME ( n c ) NP = c ≥ 1 T : N → N we say that NTM computes f in T ( n )-time if for every x ∈ { 0 , 1 } ∗ , NTM computes f ( x ) in at most T ( | x | ) steps. The class NP contains all classes NTIME ( T ( n )) where T ( n ) Definition of Non-Deterministic Time Complexity is a polynomial of finite degree. NTIME ( T ( n )): set of all functions computable by a NTM in at most c · T ( n ) time for some constant c > 0. T 1 ( n ) = O ( T 2 ( n )) = ⇒ NTIME ( T 1 ( n )) ⊆ NTIME ( T 2 ( n )) Nabil Mustafa The Class NP Nabil Mustafa The Class NP
An equivalence An equivalence Claim Claim The two different definitions of NP are equivalent. The two different definitions of NP are equivalent. x ∈ NTIME ( n c ) = ⇒ x ∈ NTIME ( n c ) ⇒ x ∈ NP x ∈ NP = Proof. Proof. If L ∈ NTIME ( n c ) there exists a NTM N that decides L If L ∈ NP there exists a poly-time TM M ( x , u ) that | u | = O ( | x | c ) If x ∈ L If x ∈ L , ∃ u such that M ( x , u ) = 1 There exists an accepting path of length O ( n c ) If x / ∈ L , no u such that M ( x , u ) = 1 This path determined by rule applied at each t Certificate: These sequence of rules leading to acceptance Construct a NTM N as follows: Size of the certificate: O ( n c ) The transition table is exactly that of M If x / ∈ L Given input x , first ‘guess’ the certificate u Write down u using non-deterministic choices, and run M ( x , u ) No sequence of states will ever lead to accepting state If x ∈ L , there exists some guess of u that will accept. Can verify in polynomial time given the sequence of rules Length of u is poly-time, hence NTM takes poly-time. Nabil Mustafa The Class NP Nabil Mustafa The Class NP
Recommend
More recommend