Presentation is loading. Please wait.

Presentation is loading. Please wait.

חישוביות וסיבוכיות Computability and Complexity Lecture 7 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA.

Similar presentations


Presentation on theme: "חישוביות וסיבוכיות Computability and Complexity Lecture 7 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA."— Presentation transcript:

1 חישוביות וסיבוכיות Computability and Complexity Lecture 7 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA

2 Outline Last week: Time complexity The class P Today: Non-deterministic TM The class NP

3 Last Week: Time Complexity Definition: Let M be a TM that halts on all inputs. The time complexity of M is a function f:N  N, where f(n) is the maximum number of steps that M performs on any input of length n. Definition: Let t: N  R +. The complexity class TIME(t(n)), is the collection of all languages that are decidable by an O(t(n)) time Turing machine.

4 Complexity vs. Computability Computability: Church-Turing thesis “all reasonable models of computation are equivalent” Complexity: Choice of model may affect running time. Which model should we use to classify the time complexity of problems? Idea: choose a classification system that is not sensitive to relatively small differences in complexity.

5 Single and Multi-tape TM’s Theorem: Let t(n) be a function, where t(n)  n. Then every t(n)-time multiple TM has an equivalent O(t 2 (n))-time single-tape TMs. All reasonable (deterministic) computational models are polynomially equivalent.

6 The Class P Definition: P is the class of languages that are decidable in polynomial time on a deterministic single-tape TM. In other words,

7 Nondeterministic TM At any point in a computation the machine may proceed according to several possibilities.  : Q x   P(Q x  x {L,R}) Definition: A NTM accepts an input if there is a branch of computation that leads to the accept state.

8 The Computation Tree: Each node: represents a configuration. Each edge: a deterministic transition between two configurations. Each branch: a deterministic computation. The root: the initial configuration.

9 The Computation Tree On input w=010:  (q 0,0)=({q 1,1,R}, {q 1,0,R})  (q 1,1)=({q 1,1,R}, {q 1,0,R},{q 1,1,L})  (q 1,0)=({q 2,1,L}, {q 1,1,R}) q 0 010 1q 1 10 0q 1 10 11q 1 0 q 1 11010q 1 0

10 Simulating an NTM with a DTM Theorem: Every non-deterministic TM has an equivalent deterministic TM. Note: No reference to running time. Proof:  Every deterministic TM is a special case of non deterministic TM.  Simulating a NTM N with a DTM D:

11 Construct a tree with all possible branches of the computation. Search on the tree for accept state. Using depth first search (DFS)? May not halt! Every node has a finite number of branches, but every branch can be infinitely long. Use breadth first search (BFS). Simulating an NTM with a DTM

12 Use 3 tapes: Input tape: contains the input. Simulation tape: maintains a copy of N’s tape on some non-deterministic branch. Address tape: keeps track of D’s location in N’s computation tree (‘performs’ the BFS).

13 The Address Tape: Encodes in a lexicographic order the branches of the computation tree. 2 1 1 _ _ _ 12 1 2 3 11 1 1 2 2

14 1.Initially tape 1 contains w. Other tapes are empty. 2.Copy tape 1 to tape 2. 3.Use tape 2 to simulate N on one branch of its non deterministic computation determined by tape 3. 4.Replace the string with the lexicographically next string. Go back to 2. Simulating an NTM with a DTM

15 In stage 3: 1.Before each step - consult the next symbol on tape 3. 2.When should go directly to 4: a)If no more symbols remain on tape 3. b)If nondeterministic choice is ‘invalid’ c)In case of a reject configuration. Accept: if an accept configuration occurs.

16 Time Complexity of NTM Definition: Let N be a nondeterministic decider TM. The running time of N is the function f:N  N, where f(n) is the max. number of steps that N performs on any branch of its computation on any input of length n. Theorem: Let t(n) be a function, where t(n)  n. Then every t(n) time nondeterministic single-tape TM has an equivalent 2 O(t(n)) time deterministic single-tape TM.

17 reject accept Proof by Picture t(n) O(b t(n) ) b – max degree

18 Deterministic vs Non-deterministic Time Complexity Last week: at most polynomial difference between single-tape TM and multiple-tape TM. Today: at most exponential difference between deterministic single-tape TM and nondeterministic single-tape TM. Can we simulate NTM on DTM with only polynomial slowdown?

19 The PATH Problem Given two nodes, s and t, in a graph G, is there a directed path from s to t? PATH={ | G is a directed graph that has a directed path from s to t } Theorem: PATH  P c a d b s te

20 Hamiltonian Path A path in a directed graph G that goes through each node of G exactly once. HAMPATH={ |G is a directed graph with a Hamiltonian path from s to t} c a d b s te

21 Brute-Force Search for HAMPATH Given G with m nodes, and two nodes s, t: 1.Go over all permutations of the nodes in G. 2.For each permutation verify whether it is a Hamiltonian path that starts with s and ends with t. Number of possible paths m! = θ (m m ) => Exponential complexity

22 Polynomial Verifiability Finding a Hamiltonian path seems to be hard. However, given a path, it is possible to verify that it is Hamiltonian in polynomial time. c a d b s te

23 Another Example: Compositeness A natural number is composite if it is a product of two integers greater than 1. COMPOSITES = {x | x=pq, for integers p,q>1} COMPOSITES can be verified in poly-time: any divisor of x can serve as a certificate.

24 Are all problems Verifiable in Polynomial Time? HAMPATH – complement of HAMPATH: determine whether a graph does not have a Hamiltonian path. But how can you verify nonexistence of something? Seems like we must go over all paths… It is unknown whether HAMPATH can be verified in polynomial time.

25 Verifier for a Language Definition: A verifier for a language A is an algorithm V, where A = {w |  string c s.t. V accepts } V’s running time is measured in terms of |w| A is polynomially verifiable if it has a poly-time V c is the certificate or proof of membership in A V can verify that w is in A, given a certificate, c

26 The Class NP Definition: NP is the class of languages that have a polynomial time verifier. NP is an important class: 1.Contains problems of practical interest, such as HAMPATH and COMPOSITES (we’ll see many more). 2.Captures the notion of efficiently verifiable ‘proof’ (we may try and use it to model abstract things such as ‘creativity’). 3.Related to THE central open question in computer science (is P equal to NP?).

27 NP: Non-deterministic Poly-time Example: Nondeterministic TM that decides HAMPATH N 1 = “On input 1.Write a list of m numbers, p 1,…p m, where m is the number of nodes in G. (Nondeterministic) 2.Check for repetitions in the list – if exists reject. 3.Check that s=p 1 and t=p m if not- reject. 4.For 1  i<m, check that all (p i,p i+1 ) are edges in G. If not reject, otherwise, accept.” Note: N 1 runs in polynomial time.

28 NP – Alternative Definition Theorem: A language is in NP iff it can be decided by some non-deterministic polynomial time TM. Corollary: Any language in NP can be decided in exponential time (why?). Proof idea (of theorem):  NTM simulates verifier by guessing the certificate.  Verifier simulates NTM by using the accepting branch of the NTM.

29 Let A  NP and let V be a polynomial time verifier for A. The following NTM N decides A in polynomial time. N = “On input w of length n. 1.Non-deterministically select string c of length ≤ n k. 2.Run V on input. 3.If V accepts, accept; Otherwise, reject.” Proof: First Direction

30 Assume that A is decided by a polynomial time NTM N. The following V is a polynomial time verifier. V = “ On input. 1.Simulate N on input w (c is the choices made along the nondeterministic computation of N). 2.If this branch of N’s computation accepts, accept; Otherwise, reject. Proof: Second Direction

31 Non-deterministic Time Complexity Definition: Let t: N  R +. The time complexity class NTIME(t(n)), is the collection of all languages that are decidable by an O(t(n)) time non-deterministic Turing machine. NTIME(t(n)) = {L | L is a language decided by a O(t(n)) time non-deterministic TM}

32 Example of a Problem in NP: CLIQUE A clique in an undirected graph is a subgraph for which every two nodes are connected. CLIQUE={ |G is undirected graph with a k-clique} 4-clique 2-clique

33 Theorem: CLIQUE ∈ NP. Proof 1: We construct a polynomial-time verifier V for CLIQUE. V = “On input,c> 1.Test whether c is a set of k nodes in G. 2.Test whether G contains all edges connecting nodes in c. 3.If both pass, accept; Otherwise, reject. “ CLIQUE is in NP

34 Proof 2: We construct a polynomial NTM N that decides CLIQUE. N = “On input 1.Non-deterministically select subset c of k nodes in G. 2.Test if G contains all edges connecting nodes in c. 3.If yes, accept; Otherwise, reject.” CLIQUE is in NP: Alternative Proof

35 Example II: SUBSET-SUM X = {x 1,…,x k } – a collection of numbers (with repetitions) t – a target number is there a subset of the collection that adds up to t? Example: ∈ SUBSET-SUM because 4 + 21 = 25

36 Theorem: SUBSET-SUM ∈ NP. Proof 1: We construct a polynomial-time verifier V for SUBSET-SUM. V = “On input,c> 1.Test whether c is a collection of numbers that sum to t. 2.Test whether S contains all numbers in c. 3.If both pass, accept; Otherwise, reject. “ SUBSET-SUM is in NP

37 Proof 2: We construct a polynomial NTM N that decides SUBSET-SUM. N = “On input 1.Non-deterministically select subset c of numbers in S. 2.Test if c is a collection of numbers that sum to t. 3.If yes, accept; Otherwise, reject.” SUBSET-SUM is in NP: Alternative Proof

38 Question: What about CLIQUE and SUBSET-SUM? As with HAMPATH, we do not know if they are in NP. These languages belong to coNP – languages whose complement is in NP. We do not know whether coNP is different from NP. coNP

39 P vs. NP P = class of languages where membership can be decided in polynomial time (quickly). NP = class of languages where membership can be verified in polynomial time (quickly).

40 P = NP ? P NP NP=P ? One of the greatest unsolved problems in theoretical Computer Science and Mathematics Best known method -- brute force:

41 עיתון הארץ 29.5.00


Download ppt "חישוביות וסיבוכיות Computability and Complexity Lecture 7 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA."

Similar presentations


Ads by Google