1 Create a NDFA which accepts the language generated by this context-free grammar. Start symbol: S S → aa S S → ε S → M M → bbb M → ab M M → b S M → E.

Slides:



Advertisements
Similar presentations
CS2303-THEORY OF COMPUTATION Closure Properties of Regular Languages
Advertisements

Properties of Regular Sets
Lecture 8 From NFA to Regular Language. Induction on k= # of states other than initial and final states K=0 a a* b a c d c*a(d+bc*a)*
1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
Let L= { a n b m c p : n ≠ p, and n, m, p ≥ 0} 1.Design a context-free grammar that generates L. 2. Design a PDA that accepts L.
1 Positive Properties of Context-Free languages. 2 Context-free languages are closed under: Union is context free is context-free.
1 More Properties of Regular Languages. 2 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation.
Fall 2004COMP 3351 Standard Representations of Regular Languages Regular Languages DFAs NFAs Regular Expressions Regular Grammars.
Nathan Brunelle Department of Computer Science University of Virginia Theory of Computation CS3102 – Spring 2014 A tale.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
1 Let L= { w= u v : u  {a, b}*, v  {c, d}* and |u|= |v|} 1.Design a context-free grammar that generates L. 2.Use your grammar and the construction from.
1 For each language, give a regular expression that generates the language and a DFA that accepts it. L 1 = { w  {0, 1}* : has both 00 and 11 as substrings}
1 State SymbolRead- Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
1 3-COLOURING: Input: Graph G Question: Does there exist a way to 3-colour the vertices of G so that adjacent vertices are different colours? 1.What could.
1 Problem of the Day: Factor (ab) k as xyz in all ways such that y ≠ ε.
Problem of the Day: Factor (ab) k as xyz in all ways such that y ≠ ε.
1 Assignment #1 is due on Friday. Any questions?.
1 Which languages do the following TM’s accept over the alphabet Σ={a, b}? Recall: A TM M accepts a language L defined over an alphabet Σ if M halts on.
TK PrasadPumping Lemma1 Nonregularity Proofs. TK PrasadPumping Lemma2 Grand Unification Regular Languages: Grand Unification (Parallel Simulation) (Rabin.
1 L= { w c w R : w  {a, b}* } is accepted by the PDA below. Use a construction like the one for intersection for regular languages to design a PDA that.
CS 3240 – Chapter 4.  Closure Properties  Algorithms for Elementary Questions:  Is a given word, w, in L?  Is L empty, finite or infinite?  Are L.
Class Discussion Can you draw a DFA that accepts the language {a k b k | k = 0,1,2,…} over the alphabet  ={a,b}?
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Properties of Regular Languages
1 Suppose I construct a TM M f which: 1. Preserves its input u. 2. Simulates a machine M b on input ε. 3. If M b hangs on input ε, force an infinite loop.
Pumping Lemma for CFLs. Theorem 7.17: Let G be a CFG in CNF and w a string in L(G). Suppose we have a parse tree for w. If the length of the longest path.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 9 Mälardalen University 2006.
Critique this PDA for L= { u u R v v R : u ∈ {0,1}* and v ∈ {0,1}+ } u0εu0 u1εu1 uεεvε v00vε v11vε vεεfε sεεtε t0εt0 t1εt1 t00tε t11tε tεεuε After you.
1 Find as many examples as you can of w, x, y, z so that w is accepted by this DFA, w = x y z, y ≠ ε, | x y | ≤ 7, and x y n z is in L for all n ≥ 0.
Young CS 331 D&A of Algo. NP-Completeness1 NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and.
1.Draw a parse tree for the following derivation: S  C A C  C A b b  b b A b b  b b B b b  b b a A a a b b  b b a b a a b b 2. Show on your parse.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
1 1. Which of these sequences correspond to Hamilton cycles in the graph? (a) (b) (c) (d) (e)
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
P Symbol Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory III Properties of Regular Languages 1.Closure 2.Union 3.Concatenation 4.Complement(Negation)
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
CSE 332: NP Completeness, Part II Richard Anderson Spring 2016.
1 Use the pumping theorem for context-free languages to prove that L= { a n b a n b a p : n, p ≥ 0, p ≥ n } is not context-free. Hint: For the pumping.
Theory of Computation. Introduction to The Course Lectures: Room ( Sun. & Tue.: 8 am – 9:30 am) Instructor: Dr. Ayman Srour (Ph.D. in Computer Science).
CSE 105 theory of computation
Standard Representations of Regular Languages
Properties of Context-Free Languages
PROPERTIES OF REGULAR LANGUAGES
FORMAL LANGUAGES AND AUTOMATA THEORY
CSE 105 theory of computation
Formal Language & Automata Theory
PDAs Accept Context-Free Languages
Decision Properties of Regular Languages
Deterministic PDAs - DPDAs
Closure Properties of Context-Free languages
Elementary Questions about Regular Languages
Closure Properties of Regular Languages
1. for (i=0; i < n; i+=2) if (A[i] > A[i+1]) swap(A[i], A[i+1])
Department of Computer Science & Engineering
Chapter 4 Properties of Regular Languages
CS 583 Fall 2006 Analysis of Algorithms
Properties of Context-Free languages
Convert to a DFA: Start state: Final States: State Symbol Read- Q E(Q)
NP-Completeness Reference: Computers and Intractability: A Guide to the Theory of NP-Completeness by Garey and Johnson, W.H. Freeman and Company, 1979.
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
CSE 105 theory of computation
Algorithms to Answer Questions about Regular Languages
CSE 105 theory of computation
Presentation transcript:

1 Create a NDFA which accepts the language generated by this context-free grammar. Start symbol: S S → aa S S → ε S → M M → bbb M → ab M M → b S M → E E → aa

2 Announcements Assignment #3: Due Wed. Oct. 20. Our midterm is Friday October 22 in class. Midterm tutorial: Tues. Oct. 19, 5pm-8pm, ECS 116. The preliminary final exam schedule has been posted.

3 Algorithms to Answer Questions about Regular Languages if (if23==23) x= -23.2e23-6;

4 The first step of a compiler is to break your program into tokens. Tokens: Keywords: if Brackets: ( ) Variables: if23 x Assignment: = Math Operator: - if (if23==23) x= -23.2e23-6; Logical: == Delimiter: ; Double:-23.2e23 Integers: 23 6

5 Keywords: if ⋃ while ⋃ int ⋃ double ⋃ switch ⋃ …. Variables: Not a Keyword but of the form: (a-z ⋃ A-Z)(a-z ⋃ A-Z ⋃ 0-9 ⋃ _ )* Non-negative Integers: N= (0 ⋃ (1-9)(0-9)*) Numeric values: (Ф* ⋃ - ) ⋃ N (Ф* ⋃. (0-9)*) (Ф* ⋃ (e ⋃ E)(Ф* ⋃ + ⋃ - ) N )

6 The pumping lemma and also closure properties are used to prove languages are not regular. Regular languages are closed under: union concatenation Kleene star complement intersection exclusive or difference reversal

7 There are algorithms for the following questions about regular languages: 1. Given a DFA M and a string w, is w  L(M)? 2. Given a DFA M, is L(M) = Ф ? 3. Given a DFA M, is L(M) = Σ* ? 4. Given DFA’s M 1 and M 2, is L(M 1 )  L(M 2 )? 5. Given DFA’s M 1 and M 2, is L(M 1 ) = L(M 2 )? How can we use these to check correctness of student answers for the java tutorial?

8 Java Regular expression tutorial: S= student answer, T= teacher answer Strings student generates but should not. Is S intersect the complement of T = Ф?

9 Java Regular expression tutorial: S= student answer, T= teacher answer Strings student should generate but does not. Is T intersect the complement of S = Ф?

10 The Pumping Lemma for Regular Languages: If L is a language accepted by a DFA with k states, and w  L, |w| ≥ k, then  x, y, z such that 1. w = x y z, 2. y ≠ ε, 3. | x y | ≤ k, and 4. x y n z is in L for all n ≥ 0. The pumping lemma is NOT strong enough to work directly to prove that certain languages are not regular.

11 Let L be a language which has a constant k such that for all w  L, |w| ≥ k,  x, y, z such that 1. w = x y z, 2. y ≠ ε, 3. | x y | ≤ k, and 4. x y n z is in L for all n ≥ 0. Then you CANNOT conclude that L is regular. Counterexample: See assignment 3. L 1 = { u u R v : u, v in {a, b} + } This is necessary but not sufficient for a language to be regular.

12 Table 1: Comparing polynomial and exponential time complexity. Assume a problem of size one takes seconds (1 microsecond). Size n n second second second second second second n2n second second second second second second n3n second0.008 second0.027 second0.064 second0.125 second0.216 second n5n5 0.1 second3.2 second24.3 second1.7 minutes5.2 minutes13.2 minutes 2n2n second1.0 second17.9 minutes12.7 days35.7 years366 centuries 3n3n second58 minutes6.5 years3855 centuries2*10 8 centuries 1.3*10 13 centuries (from M. R. Garey and D. S. Johnson, Computers and Intractability: A Guide to the Theory of NP-completeness, W. H. Freeman, New York, 1979.)

13 Time Complexity function With present computer With computer 100 times faster With computer 1000 times faster nN1100 N11000 N1 n2n2 N210 N231.6 N2 n3n3 N34.46 N310 N3 n5n5 N42.5 N43.98 N4 2n2n N5N5+6.64N n3n N6N6+4.19N Table 2: Effect of improved technology on several polynomial and exponential time algorithms. The following table represents the size of the largest problem instance solvable in 1 hour. (from M. R. Garey and D. S. Johnson, Computers and Intractability: A Guide to the Theory of NP-completeness, W. H. Freeman, New York, 1979.)

14 Theorem 1: If Hamilton Cycle has an algorithm which is polynomial time, then so does Hamilton Path. Theorem 2: If Hamilton Path has an algorithm which is polynomial time, then so does Hamilton Cycle. Currently nobody knows a polynomial time algorithm for either problem.

15 Hamilton Path If (G has a Hamilton Cycle) return(yes) For each missing edge (u, v), if G+(u,v) has a Hamilton Cycle return(yes) Return(no) Time: O(n 2 * p(n, m+1) )

16 What is inefficient about this code? for (i=0; i < n; i++) for (j=0; j < n; j++) { tmp= G[i][j]; G[i][j]=1; G[j][i]=1; if (hamilton_cycle(n, G)) return(1); G[i][j]=tmp; G[j][i]=tmp; } return(0);

17 My solution: if (hamilton_cycle(n, G)) return(1); for (i=0; i < n; i++) for (j=i+1; j < n; j++) if (G[i][j] == 0) { G[i][j]=1; G[j][i]=1; found= hamilton_cycle(n, G); G[i][j]=0; G[j][i]=0; if (found) return(1); } return(0);

18 Hamilton Cycle: For each edge (u,v) if G + u’ + v’ + (u, u’) + (v, v’) has a Hamilton Path return (yes) Return(no) Time: O(n 2 q(n+2, m+2) )

19 My solution: for (i=0; i < n+2; i++) for (j=n; j < n+2; j++) { G[i][j]=0; G[j][i]=0;} for (i=0; i < n; i++) for (j=i+1; j<n; j++) if (G[i][j]) { G[i][n]=1; G[n][i]=1; G[j][n+1]=1;G[n+1][j]=1; if (hamilton_path(n+2, G)) return(1); G[i][n]=0; G[n][i]=0;G[j][n+1]=0;G[n+1][j]=0; } return(0);

20 Return(no) Time: O(n * q(n+2, m+2) ) Hamilton Cycle: A better solution For each neighbour of v if G + u’ + v’ + (u, u’) + (v, v’) has a Hamilton Path return (yes)

21 Some algorithms which do not work: If G-v has a Hamilton path for all vertices v this does NOT mean G has a Hamilton cycle. If G-e has a Hamilton path for all edges e this does NOT mean G has a Hamilton cycle.

22 Theorem: The Petersen graph has no Hamilton cycles. If it did, the edges would be 3-edge colourable.

23 On outside cycle: one colour used once and others used twice:

24 Colours of spoke edges are forced:

25 More forcings then stuck:

26 G-v has a Hamilton Path for all v.

27 G-e has a Hamilton Path for all e.