ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

Size: px
Start display at page:

Download "ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition"

Transcription

1 ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK 7 april 23 Classrum Edition

2 CONTEXT FREE LANGUAGES & PUSH-DOWN AUTOMATA CONTEXT-FREE GRAMMARS, CFG Problems Sudkamp Problem. (3.2.) Which language generates the grammar G given by the productions S asa aba B bb b Problem 2. (3.2.2) Find a CFG that generates the language: Problem 3. (3.2.4) Find a CFG that generates the language Problem 4. (3.2.5) Consider the grammar What language does it generate? L(G) = { a n b m c m d 2n n, m > }. L(G) = { a n b m n m 2n}. S abscb λ B bb b Problems Lewis-Papadimitriou Construct context free grammars to accept the following languages. Problem 5. Problem 6. (2.4b) {w w starts and ends with the same symbol} (2.4c) {w w is odd} Problem 7. (2.4d) {w w is odd and its middle symbol is } 2

3 Problem 8. {w#x w R is a substring of x, where w, x {a, b} * } Problem 9. { n n n>} U { n 2n n>} Problem. { i j 2 k i j or j k} Problem. Binary strings with twice as many s as s. Problems Linz Problem 2. (34/8c): Find a Context-Free Grammar for the following language: Problem 3. (34/8c): Ambiguity L = {a n b m c k : k = n + m } L = {a n b m c k : k n + m } (Variation on a theme). Problem 4. Explain why the grammar below is ambiguous. S A B A AA S B BB S Problem 5. Given the following ambiguous context free grammar S Ab aab A a Aa B b (a) Find the string s generated by the grammar that has two leftmost derivations. Show the derivations. (b) Show the two derivation trees for the string s. (c) (d) Find an equivalent unambiguous context-free grammar. Give the unique leftmost derivation and derivation tree for the string s generated from the unambiguous grammar above. ATT REDOVISA ORDINARIE Deadline Ö5 Problem 4 & Problem 8 ATT REDOVISA EXTRA Deadline Ö7 Problem 9 & Problem 5 3

4 PUSH-DOWN AUTOMATA, PDA Sudkamp Problem. CH Let M be the PDA that accepts even-length palindromes over {a, b}. That is, L(M) = { w w R w {a, b}*} Where non-determinism allows the machine to guess when the middle of the string has been reached. b λ/b a λ/a b B/λ a A/λ q λλ/λ q which in Linz notation looks like this: b, λ B a, λ A b, B λ a, A λ λ, λ λ q q (a, b/c stands for a, b c) a) Give the transition table of M. b) Trace all computation of the strings ab, abb, abbbb in M. c) Show that aaaa, baab L (M). d) Show that aaa, ab L (M). 4

5 Problem 2. CH8 3k Construct a PDA that accepts the set of palindromes over {a, b}. Problem 3. CH8 5a Let M be the PDA in example 8... the PDA that accepts the language R L = { wcw w { a, b} }. The stack is used to record the string w as it is processed. Stack symbols A and B represent input a and b respectively. b λ/b a λ/a q c λ/λ b B/λ a A/λ q A successful computation records the string w on the stack as it is processed. Once the c is encountered, the accepting state q is entered and the stack contains a string representing w R. The computation is completed by matching the remaining input with the elements of the stack. Trace the computation that accepts bbcbb. 5

6 NPDA EXAMPLES Sipser Construct non-deterministic pushdown automata to accept the following languages. (Note: ε has the same meaning as λ) Example. { n n n > } Example 2. { n 2n n } Example 3. { n n n>} U { n 2n n } Example 4. (+)* - {ww w in {,}*} (complement of ww) Linz Example 5. L = {a n b 2n : n } Example 6. Example 7. L = {ωσω R : ω {a,b}*, σ {a,b}} Construct the NPDA corresponding to the grammar S aabb aaa A abb a B bbb A (Problem 5 on page 94, Linz) DPDA EXAMPLES Sipser Construct deterministic pushdown automata to accept the following languages. Example 8. { n n n>} U { n 2n n>} Example 9. Binary strings that contain an equal number of s and s. 6

7 Example. Binary strings with twice as many s as s. Example. Binary strings that start and end with the same symbol and have the same number of s as s. Linz Example 2. Show that L = {a n b m : m n + 2} is deterministic. (Problem 2 on page 99.) Problems Linz Problem 6. (34/8c): Find a Context-Free Grammar for the following language: L = {a n b m c k : k = n + m } Problem 7. (34/8c): L = {a n b m c k : k n + m } (Variation on a theme). Ambiguity Problem 8. Explain why the grammar below is ambiguous. S A B A AA S B BB S ATT REDOVISA ORDINARIE Deadline Ö6 Example 6 & Example 8 ATT REDOVISA EXTRA Deadline Ö8 Problem 2 & Problem 7

8 PUMPING LEMMA: CONTEXT-FREE OR NOT? Problem. Show that the following language on Σ = {a, b, c} is not context-free. L = {a n b j c k : k = jn}. Problem 2. Show that the following language on Σ = {a, b} is not context-free: L = { ww R a w : w {a, b}*} Problem 3. (CH8 7c Sudkamp) Using the pumping lemma prove that the language below is not context-free. L i 2i = { a b a i i } Problem 4. Problem 5. (CH8 8a Sudkamp) Prove that the language i 2i j L = { a b c i, j } is context-free. (7 page 22, Linz) We want to prove that the language L = {a n b n : n and n is not a multiple of 5} is a context-free language. Problem 6. { k i i j j k i, j, k > } Problem 7. {w#x w is a substring of x, where w, x are in {,}*}. Problem 8. { i i j i i, j > } Problem 9. The complement of {( n n ) m m, n > }. Problem. 2.8 a. (Lewis-Papadimitriou): A = { n n n n n >= }. Problem. 2.8 b (Lewis-Papadimitriou): B = { n # 2n # 3n n >= }. Problem c (Lewis-Papadimitriou): C = { w#x w is a substring of x, where w, x {a, b}*}. ATT REDOVISA ORDINARIE DEADLINE Ö7 Problem 4 & Problem ATT REDOVISA EXTRA DEADLINE Ö9 Problem 2 & Problem 8

9 SOLUTIONS CONTEXT-FREE GRAMMARS, CFG Sudkamp examples Problem Which language generates the grammar G given by the productions S asa aba B bb b L(G) = { a n b m a n n >, m > }. The rule S asa recursively builds an equal number of a s on each end of the string. The recursion is terminated by the application of the rule S aba, ensuring at least one leading and one trailing a. The recursive B rule then generates any number of b s. To remove the variable B from the string and obtain a sentence of the language, the rule B b must be applied, forcing the presence of at least one b. Problem Find a CFG that generates the language L(G) = { a n b m c m d 2n n, m > }. The relationship between the number of leading a s and trailing d s in the language indicates that the recursive rule is needed to generate them. The same is true for b s and c s. Derivations in the grammar S asdd A A bac bc 9

10 generate strings in an outside-to-inside manner. The S rules produce the a s and d s while the A rules generate b s and c s. The rule A bc, whose application terminates the recursion, ensures the presence of the substring bc in every string in the language. Problem Find a CFG that generates the language L(G) = { a n b m n m 2n}. S asb asbb λ The first recursive rule of G generates a trailing b for every a, while the second generates two b s for each a. Thus there is at least one b for every a and at most two, as specified in the language. Problem 4. REDOVISNINGSUPPGIFT Problems Lewis-Papadimitriou Construct context free grammars to accept the following languages. Σ = {, } Problem 5. (2.4b) {w w starts and ends with the same symbol} S A A A A A λ Problem 6. (2.4c) {w w is odd} S A A S S λ

11 Problem 7. (2.4d) {w w is odd and its middle symbol is } S S S S S Problem 8. REDOVISNINGSUPPGIFT Problem 9. REDOVISNINGSUPPGIFT Problem. { i j 2 k i j or j k} S AC BC DE DF A A A B B B C 2 2C D D E E E2 F 2 F2 F2 Problem. Binary strings with twice as many s as s. S λ SSS SSS SSS

12 Problem 2. Find a Context-Free Grammar for the following language: L = {a n b m c k : k = n + m } Let G be the grammar with productions: S asc B B bbc λ Claim: L(G) = L Proof: Consider the following derivation: S * a n Sc n a n Bc n * a n b m Bc m c n a n b m (n + m) c (where the first * applies S asc n times, the second B bbc m times) Since all words in L(G) must follow this pattern in their derivations, it is clear that L(G) L Consider w L, w = a n b m c (n+m) for some n, m The derivation S * a n Sc n a n Bc n * a n b m Bc m c n a n b m (n + m) c clearly produces w for any n, m. L L(G) L = L(G) G is a CFG for L 2

13 Problem 3. L = {a n b m c k : k n + m } (Variation on a theme). Let G be the grammar with productions: S EcC aae AU A aa λ B bb λ C cc λ E aec F F bfc λ U auc V V bvc bb Note: L(E) = {a n b m c k : k = n + m } (from 4(a) in Linz book) Let L = {a n b m c k : k < n + m }, L2 = {a n b m c k : k > n + m } Claim: L(G) = L = L L2 Proof: Consider the leftmost productions following S EcC S EcC * a n b m c (n+m) cc * a n b m c (n+m) cc k C a n b m c (n+m) cc k = a n b m c (n+m+k+) (where the first * follows from 4(a), the second from k repetitions of { C cc }) Since (n+m) < (n+m+k+), L(EcC) L2 L 3

14 Consider the leftmost productions following S aae S aae * aa k AE aa k E * aa k a n b m c (n+m) c = a (n+k+) b m c (n+m) (where the first * follows from k repetitions of { A aa }, the second from 4(a)) Since (n+m+k+) > (n+m), L(aAE) L L Consider the leftmost productions following S AU S AU * a k AU a k U * a k a n Uc n a k a n Vc n * a k a n b m Vc m c n a k a n b m bbc m c n * a k a n b m bb j Bc m c n a k a n b m bb j c m c n = a (k+n) b (m+j+) c (m+n) (where the first, second, third and fourth * are k, n, m, and j repetitions of { A aa }, { U auc }, { V bvc }, and { B bb }, respectively) Since ((k+n)+(m+j+)) > (m+n), L(AU) L L L(G) = L(S) = L(EcC) L(aAE) L(AU) L L2 = L Consider w L, w = a n b m c (n+m+k) for some n, m, k, with k > Then w has the leftmost derivation: S EcC * a n b m c (n+m) cc * a n b m c (n+m) cc (k-) C a n b m c (n+m) cc k(k-) = a n b m c (n+m+k) = w L2 L(G) 4

15 Consider w L2, w = a (n+j) b (m+k) c (n+m) for some j, k, m, n, with j+k > If k =, w has the leftmost derivation: S aae * aa (j-) AE aa (j-) E * aa (j-) a n Ec n aa (j-) a n Fc n * aa (j- ) a n b m Fc m c n aa (j-) a n b m c m c n = a (j+n) b (+m) c (m+n) = w L (k = ) L(G) If k >, then w has the leftmost derivation: S AU * a j AU a j U * a j a n Uc n a j a n Vc n * a j a n b m Vc m c n a j a n b m bbc m c n a j a n b m bb (k-) Bc m c n a j a n b m bb (k-) c m c n = a (j+n) b (m+k) c (m+n) = w L (k > ) L(G) L L(G) L = L L2 L(G) L = L(G) Ambiguity Problem 4. Explain why the grammar below is ambiguous. S A B A AA S B BB S The grammar is ambiguous because we can find strings which have multiple derivations: S A AA S B S A AA S A Problem 5. REDOVISNINGSUPPGIFT 5

16 PUSH-DOWN AUTOMATA, PDA Problem. CH Sudkamp Let M be the PDA that accepts even-length palindromes over {a, b}. That is, L(M) = { w w R w {a, b}*} Where non-determinism allows the machine to guess when the middle of the string has been reached. b λ/b a λ/a b B/λ a A/λ q λλ/λ q which in Linz notation looks like this: b, λ B a, λ A b, B λ a, A λ λ, λ λ q q (a, b/c stands for a, b c) a) Give the transition table of M. b) Trace all computation of the strings ab, abb, abbbb in M. c) Show that aaaa, baab L (M). d) Show that aaa, ab L (M). 6

17 : a) Give the transition table of M. δ ( q δ ( q δ ( q, a, λ) = {[ q, b, λ) = {[ q, A]}, B]}, λ, λ) = {[ q, } δ ( q, a, A) = {[ q, } δ ( q, b, B) = {[ q, } δ a b λ q q λ /A q λ /B q λ / λ q q A/ λ q B/ λ φ Notation: The PDA consults the current state, input symbol, and the symbol on the top of the stack to determine the machine transition. The transition function δ lists all possible transitions for a given state, symbol, and stack top combination. The value of the transition function δ ( q, a, A) {[ q, B],[ q, C]} i = j k indicates that two transitions are possible when automaton is in state qi scanning an A with A on top of the stack. The transition [ q, B] δ ( q, a, A) j i [new state, new stack top] δ(current state, current input, current stack top) q i a, A B q j 7

18 b) Trace all computation of the strings ab, abb, abbbb in M. Computations for ab: [ q, ab, [ q, ab, [ q, ab, - [ q, b, A] - [ q, λ, BA], λ, BA] Rejected. - [ q, b, A], b, A] Rejected., ab, Rejected. Computations for abb: [ q, abb, [ q, abb, [ q, abb, [ q, abb, - [ q, bb, A] - [ q, bb, A] - [ q, bb, A], abb, - [ q, b, BA] - [ q, b, BA], bb, A] Rejected. - [ q, λ, BBA], b, BA] Rejected., λ, BBA], λ, A] Rejected. Rejected. Computations for abbb: c) Show that aaaa, baab L (M). Both aaaa, baab are accepted by this PDA, so they are in L (M). [ q, aaaa, [ q, baab, - [ q, aaa, A] - [ q, aa, AA], aa, AA], a, A], λ, Accepted. - [ q, aab, B] - [ q, ab, AB], ab, AB], b, B], λ, Accepted. 8

19 d) Show that aaa, ab L (M). The computations for string aaa: [ q, aaa, [ q, aaa, [ q, aaa, [ q, aaa, - [ q, aa, A] - [ q, aa, A] - [ q, aa, A], aaa, - [ q, a, AA] - [ q, a, AA], aa, A] Rejected. - [ q, λ, AAA], λ, AAA] Rejected., a, AA], λ, A] Rejected., a, Rejected. The computations for ab are shown in part b). There is none of the computations accepting the strings, so they are not in L (M). 9

20 Problem 2. CH8 3k Sudkamp p. 252 Construct a PDA that accepts the set of palindromes over {a, b}. : Construct the PDA: M: Q = q, q } F = { { = { a, b} Γ = { A, B} q } b λ/b a λ/a q b λ/λ a λ/λ λλ/λ b B/λ a A/λ q δ ( q δ ( q δ ( q, a, λ) = {[ q, b, λ) = {[ q, λ, λ) = {[ q, } δ ( q, a, A) = {[ q, } δ ( q, b, B) = {[ q, }, A],[ q, }, B],[ q, } 2

21 Problem 3. CH8 5a Let M be the PDA in example 8... the PDA that accepts the language R L = { wcw w { a, b} }. The stack is used to record the string w as it is processed. Stack symbols A and B represent input a and b respectively. b λ/b a λ/a q c λ/λ b B/λ a A/λ q A successful computation records the string w on the stack as it is processed. Once the c is encountered, the accepting state q is entered and the stack contains a string representing w R. The computation is completed by matching the remaining input with the elements of the stack. Trace the computation that accepts bbcbb. : [ q, bbcbb, - [ q, bcbb, B] - [ q, cbb, BB], bb, BB], b, B], λ, Accepted. 2

22 NPDA EXAMPLES (Sipser) Construct non-deterministic pushdown automata to accept the following languages. (Note: ε has the same meaning as λ) Example. { n n n>} Example 2. REDOVISNINGSUPPGIFT Example 3. { n n n>} U { n 2n n>=} 22

23 Example 4. (+)* - {ww w in {,}*} (complement of ww) Linz Equivalent with Sipser Example 2, in different notation. Remark: The notation a, b/c stands for a, b c Example 5. L = {a n b 2n : n } a,a/aaa b,a/λ a,$/aa b,a/λ λ,$/$ Example 6. REDOVISNINGSUPPGIFT Example 7. corresponding to the grammar (Problem 5 one page 94, Linz) S aabb aaa A abb a B bbb A 23

24 λ,$/s λ,s/aabb λ,s/aaa λ,a/abb λ,a/a a,a/λ λ,b/bbb b,b/λ λ,$/$ DPDA EXAMPLES (Sipser) Construct deterministic pushdown automata to accept the following languages. Example 8. REDOVISNINGSUPPGIFT Example 9. Binary strings that contain an equal number of s and s. Example. REDOVISNINGSUPPGIFT 24

25 Example. Binary strings that start and end with the same symbol and have the same number of s as s. Example 2. Show that L = {a n b m : m n + 2} is deterministic. (Problem 2 on page 99, Linz a,λ/a b,a/λ b,a/λ b,$/$ b,$/$ b,$/$ b,$/$ Since there is a DPDA that accepts L, L is deterministic. 25

26 PUMPING LEMMA: CONTEXT-FREE OR NOT? Problem. Show that the following language on Σ = {a, b, c} is not context-free. L = {a n b j c k : k = jn}. Assume that L = {a n b j c k : k = jn} is a context free language. Let m m m w = a b c, w L 2 By the Pumping Lemma w can be decomposed as w = uvxyz with vxz m and vy such that uv xy z L, i i i case If i=, aaa 4243 K aab 4243 L bc L c uvxy z uv xy z = a m vy 2 b m c m L case 2 aaa 4243 K aab {{{ KbcK uv x y z If i=, uv xy z = a m 2 v b m y c m L case 3 If i=, aaa 4243 K abb{ K bbc 2 K 3c u vxy z uv xy z = a m b m 2 vy c m L 26

27 case 4 If i=, aaa 4243 K abb{{{ KbbccKc uv u xy z = a v m b x m v c yz m 2 y L case 5 aaa 42 4 K ab43 K4 bcc{ Kc u vxyz If i=, uv xy z = a m b m c 2 m vy L case 6 v or y containing ab or bc If I >, uv i xy i z would be a ab ba ab b c c Or a ab bc cb c Contrary to the assumption. Language is not context free. Problem 2. REDOVISNINGSUPPGIFT Problem 3. CH8 7c Sudkamp Using the pumping lemma prove that the language below is not context-free. i 2i L = { a b a i i } Proof: k 2k k Assume that the language is context-free. By the pumping lemma, the string w = a b a, where k is the number specified by the pumping lemma, can be decomposed into substring uvwxy that satisfy the condition length (vwx) k, length (v) + length (x) >, and i i uv wx y L, ( i ). Since the length (vwx) k, the vwx can have the following possibilities: 27

28 Case : It contains a-s and b-s ( a i b j or b i a j, < i + j k. Since length (vwx) k, it cannot have a-s at both side of b-s,). Then uv 2 wx 2 y contains a b a b a. It will not be in L any more. Case 2: It is contained in one of a k, k b 2 or second a k. Since the repetition in uv 2 wx 2 y will increase one of the string s lengths of k k a, b 2 or second k a, the ratio of :2: will not be satisfied. Then uv 2 wx 2 y L. There is no decomposition L that satisfies the condition of pumping lemma. Therefore, L is not context free. Problem 4. REDOVISNINGSUPPGIFT 28

29 Problem 5. 7 page 22, Linz We want to prove that the language L = {a n b n : n and n is not a multiple of 5} is a context-free language. Consider the following two languages: L ={w : w is made from a s and b s and the length of w is a multiple of ten} L 2 = {a n b n : n } Let L denote the complement of L. We have that L = L L 2. It is easy to see that L is a regular language, since we can easily build a finite automaton with states that accepts any string in this language. Since L is regular it must be that L is regular too, since regular languages are closed under complement (Theorem 4.). The language L 2 is context-free ( the grammar is: S->aSb λ). Therefore, the language L = L L 2 is also context-free, since context-free languages are closed under regular intersection (Theorem 8.5). Problem 6. { k i i j j k i, j, k > } CF. Here is a grammar that will generate the language. S A A A B B CC C D D D λ Problem 7. {w#x w is a substring of x, where w, x are in {,}*}. 29

30 Not CF. Assume for the purpose of contradiction that it is. Then let the pumping length be p. Consider the string s= p p # p p, which is in the language. If we decompose s into s=uvwxy as in the statement of the pumping lemma, there are three cases to consider. If vwx is contained in the first half of the string s, then pumping up even once (that is, taking the string uv 2 wx 2 y) will give us a string where the first half is longer than then second half, which means it can't be a substring of the second half. If vwx is contained completely in the second half, then when we pump down (that is, take the string uwy). Then the second half will be shorter than the first half (since vwx >=) and so the pumped down string will not be in the language. If vwx overlaps with the symbol #, then it must be the case that the # is contained in w, or else pumping up would give too many # symbols. So either the v will be a string of 's or the x will be a string of 's or both (We need the fact that vwx <= p here). If v is a nonempty string of 's then pumping up will give the left half more 's then the right side, so the left side will not be a subset of the right side. If x is a nonempty string of zeros then pumping down will give the right side fewer zeros than the left so the left side will not be a subset of the right side. In any case we come to the conclusion that no matter how we choose the decomposition, the conditions of the pumping lemma will be violated. So the language cannot be regular. 3

31 Problem 8. { i i j i i, j > } Not CF. Suppose it is. Then let the pumping length be p. Consider the string s= p p p, which is in the language. If we decompose s into s=uvwxy as in the statement of the pumping lemma, then an argument like the previous one shows that if vwx is anything but the lone zero between the ones, then pumping up will give you something that is not in the language. On the other hand if vwx is the lone zero, then pumping down will give you. p p p, which is not in the language. This contradicts the pumping lemma, so therefore the language is not context free. Problem 9. The complement of {( n n ) m m, n > }. CF. Here is a grammar that generates the language, with some comments on the side to explain what each non-terminal represents. S ABA A λ AC C C; n n B B D F; m n m n D D; one or more s F F; one or more s Why this works: Since R=(**)(**)* is regular, the complement ~R includes all strings which are not even of the correct form. We can Union ** complement... nondeterministically guess which pair mismatches. Problem. REDOVISNINGSUPPGIFT 3

32 Problem. REDOVISNINGSUPPGIFT. Problem c. C = { w#x w is a substring of x, where w, x {a, b}*}. Not CF. Let p be the pumping length given by the pumping lemma. We show that s = a p b p #a p b p cannot be pumped. Let s = uvxyz. Neither v nor y can contain #, otherwise s` = uv xy z does not contain # and therefore s` C. If both v and y are nonempty and occur on the LHS of the #, the string s` = uv 2 xy 2 z C because it is longer on the LHS than on the RHS. Similarly, if both strings occur on the RHS, the string s` = uv xy z C because, again, the LHS is longer than the RHS. If only one of v and y is nonempty ( vy >, therefore v and y can not be empty at the same time), treat them as if they both occurred on the same side of the # as above. The only remaining case will be where both v and y are nonempty and v is on the LHS, y on the RHS. However, vxy <= p, therefore, v can only contain b s and y can only contain a s. Hence s` = uv 2 xy 2 z C because it contains more b s on the LHS than on the RHS. Since s cannot be pumped in any way without violating the pumping lemma, C is not CF. Referenser. Linz, An Introduction to Formal Languages and Automata, Jones & Bartlett 2 2. Sipser, Introduction to the Theory of Computation, PWS Sudkamp, Languages and Machines, Addison Wesley Lewis-Papadimitriou, Elements of the Theory of Computation, Prentice Hall

Section 1 (closed-book) Total points 30

Section 1 (closed-book) Total points 30 CS 454 Theory of Computation Fall 2011 Section 1 (closed-book) Total points 30 1. Which of the following are true? (a) a PDA can always be converted to an equivalent PDA that at each step pops or pushes

More information

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen Pushdown automata Twan van Laarhoven Institute for Computing and Information Sciences Intelligent Systems Version: fall 2014 T. van Laarhoven Version: fall 2014 Formal Languages, Grammars and Automata

More information

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harry Lewis October 8, 2013 Reading: Sipser, pp. 119-128. Pushdown Automata (review) Pushdown Automata = Finite automaton

More information

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014 Q.2 a. Show by using Mathematical Induction that n i= 1 i 2 n = ( n + 1) ( 2 n + 1) 6 b. Define language. Let = {0; 1} denote an alphabet. Enumerate five elements of the following languages: (i) Even binary

More information

Fundamentele Informatica II

Fundamentele Informatica II Fundamentele Informatica II Answer to selected exercises 5 John C Martin: Introduction to Languages and the Theory of Computation M.M. Bonsangue (and J. Kleijn) Fall 2011 5.1.a (q 0, ab, Z 0 ) (q 1, b,

More information

Theory of Computation - Module 3

Theory of Computation - Module 3 Theory of Computation - Module 3 Syllabus Context Free Grammar Simplification of CFG- Normal forms-chomsky Normal form and Greibach Normal formpumping lemma for Context free languages- Applications of

More information

Theory of Computation

Theory of Computation Fall 2002 (YEN) Theory of Computation Midterm Exam. Name:... I.D.#:... 1. (30 pts) True or false (mark O for true ; X for false ). (Score=Max{0, Right- 1 2 Wrong}.) (1) X... If L 1 is regular and L 2 L

More information

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor 60-354, Theory of Computation Fall 2013 Asish Mukhopadhyay School of Computer Science University of Windsor Pushdown Automata (PDA) PDA = ε-nfa + stack Acceptance ε-nfa enters a final state or Stack is

More information

CS500 Homework #2 Solutions

CS500 Homework #2 Solutions CS500 Homework #2 Solutions 1. Consider the two languages Show that L 1 is context-free but L 2 is not. L 1 = {a i b j c k d l i = j k = l} L 2 = {a i b j c k d l i = k j = l} Answer. L 1 is the concatenation

More information

Homework 4. Chapter 7. CS A Term 2009: Foundations of Computer Science. By Li Feng, Shweta Srivastava, and Carolina Ruiz

Homework 4. Chapter 7. CS A Term 2009: Foundations of Computer Science. By Li Feng, Shweta Srivastava, and Carolina Ruiz CS3133 - A Term 2009: Foundations of Computer Science Prof. Carolina Ruiz Homework 4 WPI By Li Feng, Shweta Srivastava, and Carolina Ruiz Chapter 7 Problem: Chap 7.1 part a This PDA accepts the language

More information

Theory of Computation (IV) Yijia Chen Fudan University

Theory of Computation (IV) Yijia Chen Fudan University Theory of Computation (IV) Yijia Chen Fudan University Review language regular context-free machine DFA/ NFA PDA syntax regular expression context-free grammar Pushdown automata Definition A pushdown automaton

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1 Table of Contents: Week 1: Preliminaries (set algebra, relations, functions) (read Chapters

More information

CISC4090: Theory of Computation

CISC4090: Theory of Computation CISC4090: Theory of Computation Chapter 2 Context-Free Languages Courtesy of Prof. Arthur G. Werschulz Fordham University Department of Computer and Information Sciences Spring, 2014 Overview In Chapter

More information

Introduction to Theory of Computing

Introduction to Theory of Computing CSCI 2670, Fall 2012 Introduction to Theory of Computing Department of Computer Science University of Georgia Athens, GA 30602 Instructor: Liming Cai www.cs.uga.edu/ cai 0 Lecture Note 3 Context-Free Languages

More information

Automata Theory CS F-08 Context-Free Grammars

Automata Theory CS F-08 Context-Free Grammars Automata Theory CS411-2015F-08 Context-Free Grammars David Galles Department of Computer Science University of San Francisco 08-0: Context-Free Grammars Set of Terminals (Σ) Set of Non-Terminals Set of

More information

CS 341 Homework 16 Languages that Are and Are Not Context-Free

CS 341 Homework 16 Languages that Are and Are Not Context-Free CS 341 Homework 16 Languages that Are and Are Not Context-Free 1. Show that the following languages are context-free. You can do this by writing a context free grammar or a PDA, or you can use the closure

More information

Computational Models - Lecture 4

Computational Models - Lecture 4 Computational Models - Lecture 4 Regular languages: The Myhill-Nerode Theorem Context-free Grammars Chomsky Normal Form Pumping Lemma for context free languages Non context-free languages: Examples Push

More information

Concordia University Department of Computer Science & Software Engineering

Concordia University Department of Computer Science & Software Engineering Concordia University Department of Computer Science & Software Engineering COMP 335/4 Theoretical Computer Science Winter 2015 Assignment 3 1. In each case, what language is generated by CFG s below. Justify

More information

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the

More information

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA) CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA) Objectives Introduce the Pumping Lemma for CFL Show that some languages are non- CFL Discuss the DPDA, which

More information

Languages, regular languages, finite automata

Languages, regular languages, finite automata Notes on Computer Theory Last updated: January, 2018 Languages, regular languages, finite automata Content largely taken from Richards [1] and Sipser [2] 1 Languages An alphabet is a finite set of characters,

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2016 http://cseweb.ucsd.edu/classes/sp16/cse105-ab/ Today's learning goals Sipser Ch 2 Define push down automata Trace the computation of a push down automaton Design

More information

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu Part 4 out of 5 ETH Zürich (D-ITET) October, 12 2017 Last week, we showed the equivalence of DFA, NFA and REX

More information

CSE 355 Test 2, Fall 2016

CSE 355 Test 2, Fall 2016 CSE 355 Test 2, Fall 2016 28 October 2016, 8:35-9:25 a.m., LSA 191 Last Name SAMPLE ASU ID 1357924680 First Name(s) Ima Regrading of Midterms If you believe that your grade has not been added up correctly,

More information

download instant at Assume that (w R ) R = w for all strings w Σ of length n or less.

download instant at  Assume that (w R ) R = w for all strings w Σ of length n or less. Chapter 2 Languages 3. We prove, by induction on the length of the string, that w = (w R ) R for every string w Σ. Basis: The basis consists of the null string. In this case, (λ R ) R = (λ) R = λ as desired.

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1 Tale of Contents: Week 1: Preliminaries (set alger relations, functions) (read Chapters

More information

Homework 5 - Solution

Homework 5 - Solution DCP3122 Introduction to Formal Languages, Spring 2015 Instructor: Prof. Wen-Guey Tzeng Homework 5 - Solution 5-May-2015 Due: 18-May-2015 1. Given Σ = {a, b, c}, find an NPDA that accepts L = {a n b n+m

More information

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL) CS5371 Theory of Computation Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL) Objectives Introduce Pumping Lemma for CFL Apply Pumping Lemma to show that some languages are non-cfl Pumping Lemma

More information

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen Pushdown Automata Notes on Automata and Theory of Computation Chia-Ping Chen Department of Computer Science and Engineering National Sun Yat-Sen University Kaohsiung, Taiwan ROC Pushdown Automata p. 1

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be

More information

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc.

Solution. S ABc Ab c Bc Ac b A ABa Ba Aa a B Bbc bc. Section 12.4 Context-Free Language Topics Algorithm. Remove Λ-productions from grammars for langauges without Λ. 1. Find nonterminals that derive Λ. 2. For each production A w construct all productions

More information

SFWR ENG 2FA3. Solution to the Assignment #4

SFWR ENG 2FA3. Solution to the Assignment #4 SFWR ENG 2FA3. Solution to the Assignment #4 Total = 131, 100%= 115 The solutions below are often very detailed on purpose. Such level of details is not required from students solutions. Some questions

More information

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 tree u,

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 tree u, 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 tree u, v, x, y, z as per the pumping theorem. 3. Prove that

More information

Theory of Computation (Classroom Practice Booklet Solutions)

Theory of Computation (Classroom Practice Booklet Solutions) Theory of Computation (Classroom Practice Booklet Solutions) 1. Finite Automata & Regular Sets 01. Ans: (a) & (c) Sol: (a) The reversal of a regular set is regular as the reversal of a regular expression

More information

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed

Sheet 1-8 Dr. Mostafa Aref Format By : Mostafa Sayed Sheet -8 Dr. Mostafa Aref Format By : Mostafa Sayed 09 Introduction Assignment. For = {a, } a) Write 0 strings of the following languages i) All strings with no more than one a,,, a, a, a, a, a, a, a ii)

More information

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska LECTURE 11 CHAPTER 3 CONTEXT-FREE LANGUAGES 1. Context Free Grammars 2. Pushdown Automata 3. Pushdown automata and context -free

More information

Computational Models - Lecture 4 1

Computational Models - Lecture 4 1 Computational Models - Lecture 4 1 Handout Mode Iftach Haitner and Yishay Mansour. Tel Aviv University. April 3/8, 2013 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

More information

Context-Free and Noncontext-Free Languages

Context-Free and Noncontext-Free Languages Examples: Context-Free and Noncontext-Free Languages a*b* is regular. A n B n = {a n b n : n 0} is context-free but not regular. A n B n C n = {a n b n c n : n 0} is not context-free The Regular and the

More information

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100 EXAMPLE CFG L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa S asa L = {a n b : n 0 } L = {a n b : n 1 } S as b S as ab L { a b : n 0} L { a b : n 1} S asb S asb ab n 2n n 2n L {1 0 : n 0} L {1 0 : n 1} S

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : FORMAL LANGUAGES AND AUTOMATA THEORY Course Code : A40509 Class :

More information

Pushdown Automata. Reading: Chapter 6

Pushdown Automata. Reading: Chapter 6 Pushdown Automata Reading: Chapter 6 1 Pushdown Automata (PDA) Informally: A PDA is an NFA-ε with a infinite stack. Transitions are modified to accommodate stack operations. Questions: What is a stack?

More information

The Pumping Lemma for Context Free Grammars

The Pumping Lemma for Context Free Grammars The Pumping Lemma for Context Free Grammars Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar is in the form A BC A a Where a is any terminal

More information

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). 1a) G = ({R, S, T}, {0,1}, P, S) where P is: S R0R R R0R1R R1R0R T T 0T ε (S generates the first 0. R generates

More information

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET Regular Languages and FA A language is a set of strings over a finite alphabet Σ. All languages are finite or countably infinite. The set of all languages

More information

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a . Solution E T F a E E + T T + T F + T a + T a + F a + a E E + T E + T + T T + T + T F + T + T a + T + T a + F + T a + a + T a + a + F a + a + a E T F ( E) ( T ) ( F) (( E)) (( T )) (( F)) (( a)) . Solution

More information

CpSc 421 Final Exam December 15, 2006

CpSc 421 Final Exam December 15, 2006 CpSc 421 Final Exam December 15, 2006 Do problem zero and six of problems 1 through 9. If you write down solutions for more that six problems, clearly indicate those that you want graded. Note that problems

More information

CSE 105 Homework 5 Due: Monday November 13, Instructions. should be on each page of the submission.

CSE 105 Homework 5 Due: Monday November 13, Instructions. should be on each page of the submission. CSE 05 Homework 5 Due: Monday November 3, 207 Instructions Upload a single file to Gradescope for each group. should be on each page of the submission. All group members names and PIDs Your assignments

More information

Automata: a short introduction

Automata: a short introduction ILIAS, University of Luxembourg Discrete Mathematics II May 2012 What is a computer? Real computers are complicated; We abstract up to an essential model of computation; We begin with the simplest possible

More information

DM17. Beregnelighed. Jacob Aae Mikkelsen

DM17. Beregnelighed. Jacob Aae Mikkelsen DM17 Beregnelighed Jacob Aae Mikkelsen January 12, 2007 CONTENTS Contents 1 Introduction 2 1.1 Operations with languages...................... 2 2 Finite Automata 3 2.1 Regular expressions/languages....................

More information

Theory Bridge Exam Example Questions

Theory Bridge Exam Example Questions Theory Bridge Exam Example Questions Annotated version with some (sometimes rather sketchy) answers and notes. This is a collection of sample theory bridge exam questions. This is just to get some idea

More information

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions? Before We Start The Pumping Lemma Any questions? The Lemma & Decision/ Languages Future Exam Question What is a language? What is a class of languages? Context Free Languages Context Free Languages(CFL)

More information

Properties of Context Free Languages

Properties of Context Free Languages 1 Properties of Context Free Languages Pallab Dasgupta, Professor, Dept. of Computer Sc & Engg 2 Theorem: CFLs are closed under concatenation If L 1 and L 2 are CFLs, then L 1 L 2 is a CFL. Proof: 1. Let

More information

Pushdown Automata. Chapter 12

Pushdown Automata. Chapter 12 Pushdown Automata Chapter 12 Recognizing Context-Free Languages We need a device similar to an FSM except that it needs more power. The insight: Precisely what it needs is a stack, which gives it an unlimited

More information

PUSHDOWN AUTOMATA (PDA)

PUSHDOWN AUTOMATA (PDA) PUSHDOWN AUTOMATA (PDA) FINITE STATE CONTROL INPUT STACK (Last in, first out) input pop push ε,ε $ 0,ε 0 1,0 ε ε,$ ε 1,0 ε PDA that recognizes L = { 0 n 1 n n 0 } Definition: A (non-deterministic) PDA

More information

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY No part of this publication may be reproduced or distributed in any form or any means, electronic, mechanical, photocopying, or otherwise without the prior permission of the author. GATE SOLVED PAPER Computer

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation Bottom-up parsing Pumping Theorem for CFLs Recap: Going One Way Lemma: Each context-free language is accepted by some PDA. Proof (by construction): The idea: Let the stack

More information

Theory of Computation Turing Machine and Pushdown Automata

Theory of Computation Turing Machine and Pushdown Automata Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type

More information

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA TAFL 1 (ECS-403) Unit- IV 4.1 Push Down Automata 4.2 The Formal Definition of Pushdown Automata EXAMPLES for PDA 4.3 The languages of PDA 4.3.1 Acceptance by final state 4.3.2 Acceptance by empty stack

More information

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009 Chapter 1 Formal and View Lecture on the 28th April 2009 Formal of PA Faculty of Information Technology Brno University of Technology 1.1 Aim of the Lecture 1 Define pushdown automaton in a formal way

More information

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM).

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM). Automata The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled computing device which follows a predetermined

More information

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013 Q.2 a. Prove by mathematical induction n 4 4n 2 is divisible by 3 for n 0. Basic step: For n = 0, n 3 n = 0 which is divisible by 3. Induction hypothesis: Let p(n) = n 3 n is divisible by 3. Induction

More information

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8 Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8 John Martin: Introduction to Languages and the Theory of Computation Jetty Kleijn Najaar 2008 7.1 (q 0,bbcbb,Z

More information

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar TAFL 1 (ECS-403) Unit- III 3.1 Definition of CFG (Context Free Grammar) and problems 3.2 Derivation 3.3 Ambiguity in Grammar 3.3.1 Inherent Ambiguity 3.3.2 Ambiguous to Unambiguous CFG 3.4 Simplification

More information

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer. Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer. Language Generator: Context free grammars are language generators,

More information

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska LECTURE 14 SMALL REVIEW FOR FINAL SOME Y/N QUESTIONS Q1 Given Σ =, there is L over Σ Yes: = {e} and L = {e} Σ Q2 There are uncountably

More information

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam ECS 120: Theory of Computation Handout MT UC Davis Phillip Rogaway February 16, 2012 Midterm Exam Instructions: The exam has six pages, including this cover page, printed out two-sided (no more wasted

More information

CS481F01 Solutions 6 PDAS

CS481F01 Solutions 6 PDAS CS481F01 Solutions 6 PDAS A. Demers 2 November 2001 1. Give a NPDAs that recognize the following languages: (a) The set of all strings in {0, 1} that contain twice as many 1s as 0s. (answer a) We build

More information

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp )

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp ) 5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp. 91-108) Example 3.1 Consider S ε asb. What is L(S)? Solution S asb aasbb a n Sb n a n b n. L(S) = {a n b n n 0} Example 3.2 Consider

More information

Problem 2.6(d) [4 pts] Problem 2.12 [3pts] Original CFG:

Problem 2.6(d) [4 pts] Problem 2.12 [3pts] Original CFG: Problem 2.6(d) [4 pts] S X T#X X#T T#X#T X axa bxb #T# # T at bt #T ε Problem 2.12 [3pts] Original CFG: R XRX S S atb bta T XTX X ε X a b q start ε, ε $ ε, R X ε, ε R ε, ε X ε, R S ε, T X ε, T ε ε, X a

More information

Einführung in die Computerlinguistik

Einführung in die Computerlinguistik Einführung in die Computerlinguistik Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2016 1 / 22 CFG (1) Example: Grammar G telescope : Productions: S NP VP NP

More information

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach CS311 Computational Structures More about PDAs & Context-Free Languages Lecture 9 Andrew P. Black Andrew Tolmach 1 Three important results 1. Any CFG can be simulated by a PDA 2. Any PDA can be simulated

More information

CPS 220 Theory of Computation Pushdown Automata (PDA)

CPS 220 Theory of Computation Pushdown Automata (PDA) CPS 220 Theory of Computation Pushdown Automata (PDA) Nondeterministic Finite Automaton with some extra memory Memory is called the stack, accessed in a very restricted way: in a First-In First-Out fashion

More information

Introduction to Formal Languages, Automata and Computability p.1/42

Introduction to Formal Languages, Automata and Computability p.1/42 Introduction to Formal Languages, Automata and Computability Pushdown Automata K. Krithivasan and R. Rama Introduction to Formal Languages, Automata and Computability p.1/42 Introduction We have considered

More information

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Salil Vadhan October 4, 2012 Reading: Sipser, 2.2. Another example of a CFG (with proof) L = {x {a, b} : x has the same # of a s and

More information

Foundations of Informatics: a Bridging Course

Foundations of Informatics: a Bridging Course Foundations of Informatics: a Bridging Course Week 3: Formal Languages and Semantics Thomas Noll Lehrstuhl für Informatik 2 RWTH Aachen University noll@cs.rwth-aachen.de http://www.b-it-center.de/wob/en/view/class211_id948.html

More information

Automata and Computability. Solutions to Exercises

Automata and Computability. Solutions to Exercises Automata and Computability Solutions to Exercises Spring 27 Alexis Maciel Department of Computer Science Clarkson University Copyright c 27 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

More information

Computability and Complexity

Computability and Complexity Computability and Complexity Push-Down Automata CAS 705 Ryszard Janicki Department of Computing and Software McMaster University Hamilton, Ontario, Canada janicki@mcmaster.ca Ryszard Janicki Computability

More information

SCHEME FOR INTERNAL ASSESSMENT TEST 3

SCHEME FOR INTERNAL ASSESSMENT TEST 3 SCHEME FOR INTERNAL ASSESSMENT TEST 3 Max Marks: 40 Subject& Code: Automata Theory & Computability (15CS54) Sem: V ISE (A & B) Note: Answer any FIVE full questions, choosing one full question from each

More information

Chapter 6. Properties of Regular Languages

Chapter 6. Properties of Regular Languages Chapter 6 Properties of Regular Languages Regular Sets and Languages Claim(1). The family of languages accepted by FSAs consists of precisely the regular sets over a given alphabet. Every regular set is

More information

5 Context-Free Languages

5 Context-Free Languages CA320: COMPUTABILITY AND COMPLEXITY 1 5 Context-Free Languages 5.1 Context-Free Grammars Context-Free Grammars Context-free languages are specified with a context-free grammar (CFG). Formally, a CFG G

More information

Computational Models - Lecture 5 1

Computational Models - Lecture 5 1 Computational Models - Lecture 5 1 Handout Mode Iftach Haitner. Tel Aviv University. November 28, 2016 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University.

More information

Properties of Context-free Languages. Reading: Chapter 7

Properties of Context-free Languages. Reading: Chapter 7 Properties of Context-free Languages Reading: Chapter 7 1 Topics 1) Simplifying CFGs, Normal forms 2) Pumping lemma for CFLs 3) Closure and decision properties of CFLs 2 How to simplify CFGs? 3 Three ways

More information

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition Salil Vadhan October 11, 2012 Reading: Sipser, Section 2.3 and Section 2.1 (material on Chomsky Normal Form). Pumping Lemma for

More information

Solution Scoring: SD Reg exp.: a(a

Solution Scoring: SD Reg exp.: a(a MA/CSSE 474 Exam 3 Winter 2013-14 Name Solution_with explanations Section: 02(3 rd ) 03(4 th ) 1. (28 points) For each of the following statements, circle T or F to indicate whether it is True or False.

More information

3130CIT Theory of Computation

3130CIT Theory of Computation GRIFFITH UNIVERSITY School of Computing and Information Technology 3130CIT Theory of Computation Final Examination, Semester 2, 2006 Details Total marks: 120 (40% of the total marks for this subject) Perusal:

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/ Review of CFG, CFL, ambiguity What is the language generated by the CFG below: G 1 = ({S,T 1,T 2 }, {0,1,2}, { S

More information

Context-free Languages and Pushdown Automata

Context-free Languages and Pushdown Automata Context-free Languages and Pushdown Automata Finite Automata vs CFLs E.g., {a n b n } CFLs Regular From earlier results: Languages every regular language is a CFL but there are CFLs that are not regular

More information

CPS 220 Theory of Computation

CPS 220 Theory of Computation CPS 22 Theory of Computation Review - Regular Languages RL - a simple class of languages that can be represented in two ways: 1 Machine description: Finite Automata are machines with a finite number of

More information

CS Pushdown Automata

CS Pushdown Automata Chap. 6 Pushdown Automata 6.1 Definition of Pushdown Automata Example 6.2 L ww R = {ww R w (0+1) * } Palindromes over {0, 1}. A cfg P 0 1 0P0 1P1. Consider a FA with a stack(= a Pushdown automaton; PDA).

More information

V Honors Theory of Computation

V Honors Theory of Computation V22.0453-001 Honors Theory of Computation Problem Set 3 Solutions Problem 1 Solution: The class of languages recognized by these machines is the exactly the class of regular languages, thus this TM variant

More information

FABER Formal Languages, Automata. Lecture 2. Mälardalen University

FABER Formal Languages, Automata. Lecture 2. Mälardalen University CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010 1 Content Languages, g Alphabets and Strings Strings & String Operations Languages & Language Operations

More information

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata. Pushdown Automata We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata. Next we consider a more powerful computation model, called a

More information

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010 University of Virginia - cs3102: Theory of Computation Spring 2010 PS2 - Comments Average: 77.4 (full credit for each question is 100 points) Distribution (of 54 submissions): 90, 12; 80 89, 11; 70-79,

More information

Lecture 17: Language Recognition

Lecture 17: Language Recognition Lecture 17: Language Recognition Finite State Automata Deterministic and Non-Deterministic Finite Automata Regular Expressions Push-Down Automata Turing Machines Modeling Computation When attempting to

More information

Context-Free Languages (Pre Lecture)

Context-Free Languages (Pre Lecture) Context-Free Languages (Pre Lecture) Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Fall 2017 Dantam (Mines CSCI-561) Context-Free Languages (Pre Lecture) Fall 2017 1 / 34 Outline Pumping Lemma

More information

Context-Free Grammars and Languages. Reading: Chapter 5

Context-Free Grammars and Languages. Reading: Chapter 5 Context-Free Grammars and Languages Reading: Chapter 5 1 Context-Free Languages The class of context-free languages generalizes the class of regular languages, i.e., every regular language is a context-free

More information

Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles

Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles Automata Theory CS411-2015F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages David Galles Department of Computer Science University of San Francisco 10-0: Fun with CFGs Create

More information

5/10/16. Grammar. Automata and Languages. Today s Topics. Grammars Definition A grammar G is defined as G = (V, T, P, S) where:

5/10/16. Grammar. Automata and Languages. Today s Topics. Grammars Definition A grammar G is defined as G = (V, T, P, S) where: Grammar Automata and Languages Grammar Prof. Mohamed Hamada oftware Engineering Lab. The University of Aizu Japan Regular Grammar Context-free Grammar Context-sensitive Grammar Left-linear Grammar right-linear

More information

Automata and Computability. Solutions to Exercises

Automata and Computability. Solutions to Exercises Automata and Computability Solutions to Exercises Fall 28 Alexis Maciel Department of Computer Science Clarkson University Copyright c 28 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

More information

Pushdown Automata (2015/11/23)

Pushdown Automata (2015/11/23) Chapter 6 Pushdown Automata (2015/11/23) Sagrada Familia, Barcelona, Spain Outline 6.0 Introduction 6.1 Definition of PDA 6.2 The Language of a PDA 6.3 Euivalence of PDA s and CFG s 6.4 Deterministic PDA

More information