Checking solutions efficiently The class P : set of languages L f - - PowerPoint PPT Presentation

checking solutions efficiently
SMART_READER_LITE
LIVE PREVIEW

Checking solutions efficiently The class P : set of languages L f - - PowerPoint PPT Presentation

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 dont know how to compute f in poly-time? Nabil Mustafa 3-CNF satisfiability. Not known


slide-1
SLIDE 1

The Class NP

Nabil Mustafa Computability and Complexity

Nabil Mustafa The Class NP

Checking solutions efficiently

The class P : set of languages Lf decidable in time O(nc). Function f can be computed in poly-time. What if don’t know how to compute f in poly-time? 3-CNF satisfiability. Not known how to find an assignment. Instead, settle for languages with efficiently verifiable 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

Defining NP

NP A language L is in NP if for any x ∈ {0, 1}∗, x ∈ L ⇐ ⇒ ∃u ∈ {0, 1}p(|x|) s.t. M(x, u) = 1 where M is a poly-time TM and p(|x|) is a polynomial. u called a certificate for x Note that the implication goes both ways.

Nabil Mustafa The Class 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. Language L is in NP if for any x ∈ L, x ∈ L ⇐ ⇒ ∃u ∈ {0, 1}p(|x|) s.t. M(x, u) = 1 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. p(|x|): binary labels of k vertices, of total size k log n. 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
slide-2
SLIDE 2

Some Examples

Claim: 3-CNF satisfiability is in NP If f is satisfiable = ⇒ ∃ a satisfying assignment u The satisfying assignment u has polynomial size. Given f and u, can verify in O(nm) that u satisfies f Claim: k-coloring is in NP If G is k-colorable = ⇒ ∃ a correct coloring c The correct coloring c has polynomial size Given G and c, verify in O(m) time that c correctly colors G Subset sum: Given n integers A1, . . . , An 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

Relation between P and NP

Claim If L ∈ P , then L ∈ NP . In other words,P ⊆ NP Proof. Suppose L ∈ P decided by polynomial-time TM M Take the TM for NP as N = M u is empty string = ⇒ N takes only x If x ∈ L: N will return 1 If x / ∈ L: N will return 0

Nabil Mustafa The Class NP

Relation between NP and DTIME

Claim NP ⊆ DTIME (2nc) Proof. If L ∈ NP , we know that a poly-time TM M exists s.t. If x / ∈ L, no u will make M(x, u) = 1 if x ∈ L, ∃ a u such that M(x, u) = 1 Now this M is a poly-time TM The problem is that M doesn’t know u or how to compute u Solution: Just enumerate all possible u If it works for some u, output 1, otherwise 0 This works because: If x / ∈ L, enumeration never finds a u such that M(x, u) = 1 if x ∈ L, will find the required u Total time for enumeration: O(2p(|x|)) = O(2nc)

Nabil Mustafa The Class NP

Non-deterministic Turing Machines

Saw that a TM is defined by the tuple (Γ : symbols, Q : a set of states, δ : the transition function) The transition function: δ : Q × Γ → Q × Γ × {L, R, S} NTM : Relax δ to instead just be a relation This implies for the same (qj, σi), many possible rules (qj, σi) = ⇒ (qj′, σi′, L) (qj, σi) = ⇒ (qj′′, σi′′, R) Given an input x, the computation of a NTM is valid if a valid rule is applied at each time-step t Instead of a computation ‘path’, we have computation ‘tree’ 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
slide-3
SLIDE 3

Deciding Languages

An accepting path in this computation tree is a set of transition rules that can be applied to go to an accepting state Note: in TM , one path to follow, which accepts or rejects In NTM , some paths might accept, others might reject NTM accepts x iff there exists an accepting path 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.

Nabil Mustafa The Class NP

Non-deterministic Turing Machines

NTM computes a function such that At each computational step, M has to choose from a number

  • f rules all of which would be validly applied.

If there is some sequence of choices that end in the state qaccept then M(x) = 1. If there is no sequence of choices that end in state qaccept then we define M(x) = 0. Figure: 5 possible transition rules can be applied from the current state

Nabil Mustafa The Class NP

Different Computational paths in NTM

Nabil Mustafa The Class NP

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 qreject At the end, verify that the route takes cost less than k. If no, enter qreject Otherwise, enter qaccept

Nabil Mustafa The Class NP
slide-4
SLIDE 4

NTM Example - Traveling Salesman Problem

Only one input and one output tape. No work tape. States Q = {qstart, citya, cityb, cityc, cityd, citye, qhalt} Symbols Γ = {a, b, c, d, e} Partial transition table for NTM is Shown Q IT Γ Q OT Γ qstart a citya a qstart b cityb b qstart c cityc c citye d cityd d citye c cityc c citya b cityb b citya d cityd d cityb e citye e

Nabil Mustafa The Class NP

NTM Example - Traveling Salesman Problem

Nabil Mustafa The Class NP

Time Complexity

Running time Given: A Non-Deterministic Turing machine NTM f : {0, 1}∗ → {0, 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. Definition of Non-Deterministic Time Complexity NTIME (T(n)): set of all functions computable by a NTM in at most c · T(n) time for some constant c > 0. T1(n) = O(T2(n)) = ⇒ NTIME (T1(n)) ⊆ NTIME (T2(n))

Nabil Mustafa The Class NP

Defining NP another way

Definition NP =

  • c≥1

NTIME (nc) The class NP contains all classes NTIME (T(n)) where T(n) is a polynomial of finite degree.

Nabil Mustafa The Class NP
slide-5
SLIDE 5

An equivalence

Claim The two different definitions of NP are equivalent. x ∈ NTIME (nc) = ⇒ x ∈ NP Proof. If L ∈ NTIME(nc) there exists a NTM N that decides L If x ∈ L There exists an accepting path of length O(nc) This path determined by rule applied at each t Certificate: These sequence of rules leading to acceptance Size of the certificate: O(nc) If x / ∈ L No sequence of states will ever lead to accepting state Can verify in polynomial time given the sequence of rules

Nabil Mustafa The Class NP

An equivalence

Claim The two different definitions of NP are equivalent. x ∈ NP = ⇒ x ∈ NTIME (nc) Proof. If L ∈ NP there exists a poly-time TM M(x, u) that |u| = O(|x|c) If x ∈ L, ∃u such that M(x, u) = 1 If x / ∈ L, no u such that M(x, u) = 1 Construct a NTM N as follows: The transition table is exactly that of M Given input x, first ‘guess’ the certificate u Write down u using non-deterministic choices, and run M(x, u) If x ∈ L, there exists some guess of u that will accept. Length of u is poly-time, hence NTM takes poly-time.

Nabil Mustafa The Class NP