
CSE 105 Theory of Computationhttp://www.jflap.org/jflaptmp/ • Professor Jeanne Ferrante 1 Today’s Agenda • P and NP (7.2, 7.3) • Next class: Review Reminders and announcements: • CAPE & TA evals are open: Please participate! • Final Exam Sat Jun 4, 11:30 am – 2:29 pm in WLH 2001 • Seat Assignments: Will be out soon. Last chance to request Left-handed seat 11:59 pm today • You can bring your own a 5 in by 8 in index card (both sides) to the exam (no magnifying aids!!) 2 Time Complexity Def. Let M be a deterministic TM that always halts. The running time or time complexity of M is the function f: N N where f(n) is the maximum number of steps of the TM M on any Input of length n. Let M be a nondeterministic TM that always halts. The running time or time complexity of M is the function f: N N where f(n) is the maximum number of steps of TM M on any branch of the computation on any Input of length n. 3 Running times of decider TM’s Deterministic Nondeterministic q0 q0 f(n)= f(n) = MAX MAX number number of steps of steps qacc q qacc with on any rej input branch length with n input length n q rej qrej 4 Polynomial vs Exponential DTIME • Polynomial running time: nc for some constant c δ • Exponential running time: 2n for some real number δ > 0 If we double the input size from n to 2n: • Polynomial time: nc (2n)c = 2cnc δ δ δ δ • Exponential time: 2n 2(2n) = 22 n δ nδ 2 = ( 2 ) » Quickly explodes in size 5 Review: Big-O Notation f(n) = 4nlog(n) + 3n2 + 3n + 10 is equal to which of the following in Big-O notation? A. O(n3 ) B. O(nlog(n)) C. O(n2 ) D. None or more than one of the above 6 Time Complexity Classes + Def. Let t: N R be a function. The deterministic time complexity class DTIME(t(n)) is the collection of languages L that are decidable by a O(t(n)) deterministic, single tape TM. The nondeterministic time complexity class NTIME(t(n)) is the collection of languages L that are decidable by a O(t(n)) nondeterministic, single tape TM. 2 3 DTIME(n ) ⊂ DTIME(n )? A. TRUE B. FALSE C. Don’t Know 7 Here, model resources matter! • t(n) time deterministic multitape TM O(t(n)2 )time deterministic single tape TM • t(n) time nondeterministic single tape TM 2 O(t(n)) time deterministic single tape TM (Where t(n) >= n) 8 Example TM: M1 M1 = “On input w: 1. Scan the input from left to right to check whether it is of form {0,1}*#{0,1}*. If not, reject. If the input consists of only #, accept. 2. Return the head to the left hand end of tape. 3. Zig-zag across the tape, checking that the first unmarked symbol to the left of the # is the same as the corresponding unmarked symbol following #. If the corresponding symbols do not match, or there is no unmarked symbol left after the #, reject. Otherwise if the symbols match, mark them and continue. 4. If all symbols to the left of # have been marked, check for unmarked symbols after the #. If any unmarked symbols remain to the right of the #, reject; if none are found, accept.” L(M1) is in A.DTIME(n) B. DTIME(n2) C. DTIME(nlogn) D.None or more than 1 of the above 9 Most useful! CLASS P (DETERMINISTIC POLYNOMIAL TIME) 10 k P = Uk DTIME(n ) • P is the class of languages that can be decided in polynomial time on a deterministic, single-tape TM • Encodings in P – Need polynomial time encodings – Graph encodings • Analyze graph problems in number n of nodes; still polynomial in size of graph • Can’t use Nondeterminism • Can use multiple tapes • Brute force approach may not be enough 11 Examples in Class P • PATH = {<G,s,t> | G is a directed graph with n nodes and a directed path from node s to node t} • RELPRIME = { <x,y> | x and y are relatively prime} – Use Euclidean Algorithm to show in P • Every CFL {w | w is generated by CFG G} – Use Dynamic Programming to show in P • Most sorting algorithms To be in P, avoid brute-force searches! 12 May be exponential time deterministically! CLASS NP (NONDETERMINISTIC POLYNOMIAL TIME) 13 k Class NP = U k NTIME(n ) • For many problems, only solution is equivalent to brute force search • NP is the class of languages that can be decided in polynomial time on a non-deterministic TM • For problems in NP, best deterministic algorithms are exponential time • P ⊆ NP ! • Outstanding open problem in CS: P = NP ? • Prevailing opinion: P ≠ NP 14 Travelling Salesperson Problem in NP • Input: Encodings of – collection {C1,…Cn} of cities, – Distance k, – Distance Matrix D(i,j): distance between Ci and Cj • Problem: Is there a tour of all cities with total distance less than k? • Deterministically enumerating all tours to check distance is exponential • Best known algorithms are exponential – e.g. dynamic programming • In NP: – Nondeterministically guess a tour including all cities – Checking if a given tour has distance less than k can be done in deterministic polynomial time 15 Another Example in NP SAT = {<E>|E is a satisfiable Boolean expression} – A Boolean expression has operators AND, OR and NOT, and Boolean values which take the value 0 (false) or 1 (true) – A Boolean expression is satisfiable if there is some assignment to its variables which makes the expression evaluate to 1 (true) • x AND (y OR z) is satisfiable when x = 1, y = 1, z = 0 • x AND (NOT x) is never satisfiable 16 Decider for SAT “Given <E> of size n: 1. Nondeterministically guess an assignment of values to the variables in E 2. Check whether the assignment satisfies E; if so accept” SAT is in c A. DTIME(n ), c a constant B. DTIME (2nc), c a constant C. NTIME(nc), c a constant D. None or more than one of the above 17 Another Example In NP CLIQUE = {<G,k> | G is an undirected graph with a clique of size k} • A clique is a subgraph of G where every 2 nodes are connected by an edge • Deterministically enumerating all subsets of k nodes and checking whether they have edges between each node is exponential Checking if a given set of edges forms a clique of size k can be done in deterministic polynomial time A. True B. False C. Don’t Know 18 Summary Problems in P Problems in NP • PATH • Any problem in P • Any CFL • Traveling Salesperson • RELPRIME • SAT • ADDITION • CLIQUE… • MULTIPLICATION… 19 DOES P = NP or P ⊆ NP??? NP ?? Decidable P CF L? RegularL P = Class of languages for which membership can be decided in deterministic polynomial time NP = Class of languages for which membership can be checked in deterministic polynomial time 20 Advances in P = NP ? • Stephen Cook won the Turing Award (1982) for his 1971 paper that “laid the foundations for the theory of NP- Completeness.” Intuitively: A problem X in NP is NP-complete if showing the problem X is in P guarantees all problems in NP are in P • Cook-Levin TH: SAT is NP-complete • So if SAT is in P, then P = NP ! 21 Polynomial Time Computable Functions • A function f : Σ* Σ* is polynomial time computable if some deterministic polynomial time TM M exists that given a string w in Σ* as input, halts with just f(w) on its tape. – Note that f need not be 1-1 or onto – M must always halt – Can be any function a TM M can compute in deterministic polynomial time! TM M computes a polynomial time computable function: M = “On input w, make a second copy of w immediately after the input, and halt” A. True B. False C. Don’t Know 22 Polynomial Time Reducibility: A ≤ p B Language A is polynomial time reducible to language B, written A ≤ P B , if there is a polynomial time computable function f : Σ* Σ* such that for any w in Σ* w є A IFF f(w) є B Turns question of whether a in A into question about whether f(a) in B in polynomial time – Note that if w NOT in A, then there must be b = f(w) NOT in B If A ≤ p B and B ≤ p C THEN A ≤ p C IS A. TRUE B. FALSE C. DON’T KNOW 23 Th. 7.31: If A ≤ p B AND B IS IN P, THEN A IS IN P. • Proof: Let M be the polynomial time decider for B, and let f be the polynomial time reduction from A to B. We define a polynomial time decider N for A: N = “On input w: 1. Compute f(w) 2. Run M on input f(w) and if M accepts, accept; if M rejects, reject” Correctness: w in A IFF M accepts f(w) IFF N accepts w because f is a reduction and by construction of N. N runs in polynomial time because steps 1 and 2 both run in polynomial time (this follows in step 2 because f(w) is polynomial in the length of w, and then M runs in polynomial time on f(w)) 24 NP-Completeness A language B is NP-Complete if 1. B is in NP 2. Every A in NP is polynomial time reducible to B (A ≤ p B ) TH 7.35: If B is NP-complete and in P, then P = NP Proof: If B is NP-complete, then by definition, for every A in N P, A ≤ p B .
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages26 Page
-
File Size-