CS375: Logic and Theory of Computing

Size: px
Start display at page:

Download "CS375: Logic and Theory of Computing"

Transcription

1 CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1

2 Table of Contents: Week 1: Preliminaries (set algebra, relations, functions) (read Chapters 1-4) Weeks 3-6: Regular Languages, Finite Automata (Chapter 11) Weeks 7-9: Context-Free Languages, Pushdown Automata (Chapters 12) Weeks 10-12: Turing Machines (Chapter 13) 2

3 Table of Contents (conti): Weeks 13-14: Propositional Logic (Chapter 6), Predicate Logic (Chapter 7), Computational Logic (Chapter 9), Algebraic Structures (Chapter 10) 3

4 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Goal: To study a non-regular language called context-free language, and the machine called pushdown automaton that recognizes this language. Why do we want to study context-free language? 4

5 Can a machine recognize a language that is not regular? YES. Can have more than one production A context-free grammar has productions of the form N w where N is a non-terminal and w is any string containing terminals and/or non-terminals. 5

6 Why is the grammar called context-free grammar? Consider the rule S asb What this says is wherever you find S, you can replace it with asb. 6

7 Why is the grammar called context-free grammar? Now consider the rule CSB CaSbB This says You can replace S with asb only if it is preceded by C and followed by B. Here it imposes a condition on when S can be replaced with asb. You can apply this rule only if S appears in this particular context. Here, context is used as is generally 7 used in normal English.

8 Why is the grammar called context-free grammar? S asb CSB CaSbB ================================================== In summary, in the first case, you didn't need any context to apply the rule. You can apply it irrespective of the context in which S appears. So, grammars which contain only rules of first kind are called context-free grammars. 8

9 A context-free language is the set of strings derived from a context-free grammar. Example. { a n b n n N} is a C-F language derived from the C-F grammar Think of the strings in the following form: (ab)bb, (aabb)bb, (aaabbb)bb, S asb Λ. Example. Any regular grammar is context-free. So regular languages are C-F languages. Quiz. Find a grammar for { Answer. S asb bb. a n b n 2 n N}. 9

10 Quiz. Find a grammar for { is the reverse of w. Answer. S asa bsb Λ. R w w w {a, b}* }, where R w Example. S asa absba ab ba abba Question. What if w { a, b, c, d}? Would S asa bsb csc dsd Λ work? 10

11 Techniques for Constucting Grammars: Let L and M be two C-F grammars with disjoint sets of non-terminals and with start symbols A and B, respectively. Then L U M has grammar S A B LM has grammar S AB L* has grammar S AS Λ How about the alphabets? Why do we need a Ʌ here? 11

12 Let L and M be two C-F grammars with disjoint sets of non-terminals and with start symbols A and B, respectively. Then L U M has grammar S A B LM has grammar S AB L* has grammar S AS Λ (1) (2) (3) L*M has grammar S AS B Why? For L*, from (3), we have S AA AAS AA AAɅ S AA AAS But then from (2), we have AA AAB 12 (AA AAɅ)B = AA AAB

13 Let L and M be two C-F grammars with disjoint sets of non-terminals and with start symbols A and B, respectively. Then L U M has grammar S A B LM has grammar S AB L* has grammar S AS Λ L*M has grammar S AS B (1) (2) (3) (4) Example: find a grammar for a*b + c S A c (1) a* b A aa b (4) 13

14 Let L and M be two C-F grammars with disjoint sets of non-terminals and with start symbols A and B, respectively. Then L U M has grammar S A B LM has grammar S AB L* has grammar S AS Λ L*M has grammar S AS B Example: find a grammar for a*b*c + ac S A ac (1) (1) (2) (3) (4) a* b* c A aa B (4) b* c B bb c (4) 14

15 S asbs aasbbs a n b n S a n b n bsa a n b n bbsaa a n b n b m a m Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ Let the language of this grammar be called L Note that S asb bsa abs bas asbs bsas Ʌ We have a n b n, b n a n, (ab) n, (ba) n L 15 a n b n b m a m, a m b n a n b m, b m (a n b n )a m L

16 Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ a 2 b 5 a 3 ϵ L Why? because a 2 b 5 a 3 = (a 2 b 2 ) b 3 a 3 a 3 b 2 a 4 b 5 L Why? Because a 3 b 2 a 4 b 5 = a(a 2 b 2 ) a 4 b 4 b L L 16

17 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ some notations first: S Λ : derives in one step :derives in one or moresteps :derives in zero or moresteps S + asbasbs 17 S S

18 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ. Toshow that L L we assume that w L and show w is derived by the grammar (by induction) If w = Λ, then S Λ. Let w Λ and assume that if s L and s < w, then S + s. Show that S + w. 18

19 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ. Consider four cases: 1. w = asb for some string s. In this case, s L and s < w. So by induction we have S + s. Therefore, we have S asbs asb + asb = w. 19

20 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas 2. w = bsa for some string s. Similar to case 1. 20

21 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ. 3. w = axa for some string x. x has two more b s than a s, so x L. What do we do now? Notice, for example, if w = 4, then w = abba = aʌb bʌa. If w = 6, then w has one of the forms aabbba, ababba, abbaba, abbbaa. = aa bb bʌa, ab ab bʌa, aʌb ba ba, aʌb bb aa. derivable by the grammar 21 derivable by the grammar

22 7. Context-Free Languages & Pushdown Automata- Context-Free Languages Example. Let L be the language of strings over {a, b} with the same number of a s and b s. Does L have the following grammar? S asbs bsas Λ. 3. (conti) We claim that x can be written in the form x = ubbv where u, v L. (Can you prove it?) So by induction we have derivations S + u and S + v. Therefore, we have S asbs + aubs aubbsas + aubbvas aubbva = axa = w. 4. w = bxb for some string x. Similar to case 3. QED. 3/20/

23 First, we show that x contains at least two consecutive b s x = bb If each substring of b contains only one b, then w is of the following form: w = a a b a a b a a b a. a b a a b a a b a a If the number of substrings in b is m, then the number of substrings in a is m+1 The number of a s and the number of b s in w satisfy the following inequality: number of b s = m < m+1 <= number of a s So, x must contain at least two consecutive b s 23

24 Next, we show that x = ubbv where u, v ϵ L We will prove this by induction on the length of x. If x = 2, x = bb = ɅbbɅ, the proposition is true. We assume the proposition is true when x < 2k and show that the proposition is true when x = 2k. Let x = 2k and find the two right most consecutive b s in x. If x is of the form x = ubb, since u must be in L, so we have x = ubb = ubbʌ, u, Ʌ ϵ L Otherwise, then x must be of the following form: x = b b a y 24 for some substring y

25 Next, we show that x = ubbv (conti.) where u, v ϵ L Otherwise, then x must be of the following form: x = b b a y for some substring y Now consider the entry next to the first b on the left hand side. We have two cases: Or x = z a b b a y (1) x = z b b b a y (2) In the first case, azya ϵ L and zy < 2k, hence, by induction zy can be expressed as 25 zy = u bb s, u, s ϵ L

26 Next, we show that x = ubbv (conti.) where u, v ϵ L In the first case, azya ϵ L and zy < 2k, hence, by induction zy can be expressed as zy = u bb s, u, s ϵ L Note that bb can not be part of y. Why? If bb is part of z, we have zy = u bb t y, u, ty ϵ L or x = u bb t a b b a y u, tabbay ϵ L So if we set v = tabbay then x = ubbv, u,v ϵ L 26

27 Next, we show that x = ubbv (conti.) where u, v ϵ L In the first case, azya ϵ L and zy < 2k, hence, by induction zy can be expressed as zy = u bb s, u, s ϵ L If bb is not completely in z, then we have z = ub, y = bs, But then u, s ϵ L x = u b a b b a b s uba, abs ϵ L So x can still be expresses as x = U bb V, U, V ϵ L 27 with U = uba and V = abs

28 Next, we show that x = ubbv (conti.) where u, v ϵ L In the second case, azbbya ϵ L and zbby < 2k, hence, by induction, zbby can be expressed as zbby = s bb t, s, t ϵ L Since bb cannot be part of y, so the only possibility is y = bt, t = y, t = by or t = r bb y for some r If y = bt then s = zb and x = zbbbay = zb bb abt = u bb v, u,v ϵ L If t = y then z = s and x = z bb ba y = s bb ba y = s bb bat = u bb v with u = s, v = bat and u, v ϵ L 28

29 Next, we show that x = ubbv (conti.) where u, v ϵ L In the second case, azbbya ϵ L and zbby < 2k, hence, by induction, zbby can be expressed as zbby = s bb t, s, t ϵ L If t = by then z = sb and x = z bb ba y = sb bb ba y = s bb bbay = u bb v with u = s, v = bbay If t = r bb y for some r then z = sbbr and and u, v ϵ L x = z bb ba y = sbbr bb ba y = s bb rbbbay = u bb v with u = s, v = rbbbay and u, v ϵ L 29 Hence, the proposition is proved.

30 Examples. For a string x and letter a let na(x) be the number of a s in x. Let L = { x {a, b}* na(x) = nb(x) }. A grammar for L with start symbol E can be written as: E aebe beae Λ. Use this information to find grammars for following languages. 1. { x {a, b}* na(x) = 1 + nb(x) }. Solution: S EaE. Would S ae or S Ea work? Can this grammar generate a 4 ab 4, a 2 b 3 ab 5 a 6, b 2 aa 5 b 3? 30

31 1. { x {a, b}* na(x) = 1 + nb(x) }. Solution: S EaE. Woul S S Ea ae or work? Can this grammar generate a 4 ab 4, a 2 b 3 ab 5 a 6, b 2 aa 5 b 3? a 4 ab 4 = a (a 4 b 4 ) a 2 b 3 ab 5 a 6 = a 2 b 3 a b 5 a 5 a b 2 aa 5 b 3 = b 2 a 2 a(a 3 b 3 ) 31

32 Examples. For a string x and letter a let na(x) be the number of a s in x. Let L = {x {a, b}* na(x) = nb(x)}. A grammar for L with start symbol E can be written as: E aebe beae Λ. Use this information to find grammars for following languages. 2. {x {a, b}* na(x) = 2 + nb(x) }. Solution: S EaEaE. Why not S EaaE? Can this grammar generate a 4 ab 2 ab 2, a 2 b 3 ab 5 aa 6? a 4 ab 2 ab 2 = aa(a 2 ab 2 ab 2 ) 32 a 2 b 3 ab 5 aa 6 = (a 2 b 3 ab 5 aa 4 )aa

33 Examples. For a string x and letter a let na(x) be the number of a s in x. Let L = {x {a, b}* na(x) = nb(x)}. A grammar for L with start symbol E can be written as: E aebe beae Λ. Use this information to find grammars for following languages. 3. { x {a, b}* na(x) > nb(x) }. Solution: S EaET T aet Λ. To ensure the number of a s can be as many as possible What is T for? S EaET EaEaET EaEaEaET. 33

34 Examples. For a string x and letter a let na(x) be the number of a s in x. Let L = {x {a, b}* na(x) = nb(x)}. A grammar for L with start symbol E can be written as: E aebe beae Λ. Use this information to find grammars for following languages. 3. { x {a, b}* na(x) > nb(x) }. Solution: S EaET T aet Λ. Questions: would S EaES Ʌ or S EaES a work? None would work!!! Why? 34

35 Examples. For a string x and letter a let na(x) be the number of a s in x. Let L = {x {a, b}* na(x) = nb(x)}. A grammar for L with start symbol E can be written as: E aebe beae Λ. Use this information to find grammars for following languages. 4. {x {a, b}* na(x) < nb(x)}. Solution: S EbET T bet Λ. compare #4 with #3 35

36 7. Context-Free Languages Infinite & memory Pushdown but Automata- Pushdown Automata restricted access A pushdown automaton (PDA): a finite automaton with a stack stack operations:, push, and nop. Do nothing a PDA is an automaton that can memorize things What can we do with a PDA? can be used to model a parser (Most programming languages have deterministic PDA s ) 36

37 A PDA starts with one designated symbol on the stack. A state transition is determined by: current state input symbol top of the stack Representation: If the machine is in state i and the input letter is b and C is on top of the stack, then the stack and enter state j 37

38 Deterministic PDA: at most one legal transition for the same combination of input symbol, state and top stack symbol Nondeterminism can occur in two ways: Acceptance: A string w is accepted by a PDA if there is a path from the start state to a final state such that the input symbols 38 on the path edges concatenate to w. Otherwise, w is rejected.

39 Deterministic PDA: at most one legal transition for the same b, D combination of input symbol, state and top stack symbol Nondeterminism: the 2 nd case: b=ʌb, hence, if δ(i, Ʌ, C) is not empty, then processing δ(i, b, C) could give us two different legal transitions. Why? In addition to getting δ(i, b, C), we can get δ(i, Ʌ, C) first and then followed by δ(j, b, D) where j is the next state of δ(i, Ʌ, C) and D is a stack symbol right below C (after ping C). 39

40 Intuitively, Deterministic PDA: never have a choice Nondeterminisitic PDA: may have several alternatives how to continue A PDA is deterministic if δ(i, a, C) + δ(i, Ʌ, C) 1 for any state i, any alphabet symbol a, any stack symbol C. 40

41 Example. A PDA to accept the language { graph and as a set of 5-tuples. a n b n n > 0} as a Deterministic or nondeterministic? Consider: aaabbb Accepted a X 41

42 Quiz. How would you modify the machine to accept { n N}? a n b n Deterministic or nondeterministic? Answer: Add the instruction ( 0,, X, nop, 2), X nop 42

43 Example. A PDA to accept the language { graph and as a set of 5-tuples. a n b n n > 0} as a Instead of a, X push( a) a, a push( a) Would this PDA also work? Start X 0 1 b, a, X nop b, a 43

44 Example. A PDA to accept the language { graph and as a set of 5-tuples. a n b n n > 0} as a Take a closer look Would this PDA also work? a, X push( a) Start X a, a push( a) 0 1 b, a, X nop Deterministic or nondeterministic? b, a 44

45 Example. A PDA to accept the language { graph and as a set of 5-tuples. a n b n n > 0} as a a, X push( a) a, a push( a) Would this PDA also work? NO Start X 0 1 b, a, X nop b, a 45

46 Example. A PDA to accept the language { graph and as a set of 5-tuples. a n b n n > 0} as a a, X push( a) a, a push( a) Start X 0 b, a, X nop 1 b, a { a n b n n This PDA accepts and { a n n 0} 0} 46

47 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: 2 a s for one b Deterministic, or nondeterministic? 47

48 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: But, first, a definition Plays the role of a stack Instantaneous Description (ID) : ( current state, unconsumed input, stack contents ) e.g., (0, aaaabb, X) : start in state 0 with X on the stack and the input string being aaaabb 48

49 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: 49 accepted

50 #4, HW6 Not accepted 0, aabaabbb, X (0, abaabbb, ax) 0, baabbb, aax (1, aabbb, ax) Execution stopped 50

51 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: How do I know the PDA should be built this way? 51

52 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: First, to accept, we have two choices: Start X Start X, X nop, X nop 52

53 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: Then, build mechanism to push m a onto the stack a, X push( a) a, a push( a) a, X push ( a) a, a push ( a) Start X Start X, X nop, X nop 53

54 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: Then, build mechanism to push m a onto the stack a, X push( a) a, a push( a) a, X push ( a) a, a push ( a) Start X Start X, X nop, X nop 54 Ignore this one because it accepts { m N} a m

55 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: Then, develop mechanism to stack 2 times for a given b a from the a, X push( a) a, a push( a) b = bʌ Start X, X nop b, a, a 55

56 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: Then, build mechanism to 2 times for a given, to accept b a from the stack a 2 b a, X push( a) a, a push( a) Start X, X nop b, a, a, X nop 56

57 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: Then, build mechanism to 2 times for each, to accept b a a 2n b n from the stack a, X push( a) a, a push( a) b, a Start X, X nop b, a, a, X nop 57

58 Example. Find a PDA to accept the language { a 2n b n n N}. A solution: Then, build mechanism to 2 times for each, to accept b a a 2n b n from the stack a, X push( a) a, a push( a) b, a Remove this edge if n>0 Start X, X nop b, a, a, X nop 58

59 Example. Find a PDA to accept the language { a n b 2n n N}. Idea: build mechanism to every two s b a from the stack once for b, a nop b, a b, a nop 59

60 Example. Find a PDA to accept the language { a n b 2n n N}. Idea: build mechanism to for every two s b a from the stack once for OR b, a b, a nop b, a 60

61 Empty-Stack Acceptance. Instead of final-state acceptance, a PDA can also be defined to accept a string by the condition that the stack is empty. The two types of acceptance are equivalent in that they both define PDAs that accept the same class of languages. empty-stack PDA final-state PDA 61

62 if xxxx is accepted by the final-state Transform final-state PDA then acceptance ɅxxxxɅ is accepted to empty-stack by the acceptance: empty-stack PDA Introduce a new start state s, a new stack symbol Y, a new empty state e, and construct edges and actions as shown in the diagram below. Note that? stands for any stack symbol. 62

63 Example: given the following final-state PDA, convert it to a empty-stack PDA, X nop 63

64 Example: given the following final-state PDA, convert it to a empty-stack PDA, Y Start Y s, Y push( X ), X e, X nop 64

65 Example: given the following final-state PDA, convert it to a empty-stack PDA OR Start Y s, Y push( X ), X, Y e, X 65

66 Transform empty-stack acceptance to final-state acceptance: Introduce a new start state s, a new stack symbol Y, a new final state ƒ, and construct edges and actions as shown in the diagram below. 66

67 Theorem: The context-free (C-F) languages are exactly the languages accepted by PDAs. Proof: We ll see two algorithms, one to transform a C-F grammar into an empty-stack PDA, & one to transform an empty-stack PDA into a C-F grammar. QED. C-F grammar mpty-stack PDA final-state PDA 67

68 Transform a C-F grammar to empty-stack PDA: - The idea is to use the stack of the PDA to simulate the (leftmost) derivation of a string in the grammar. - The PDA has ONE STATE, but we allow multiple stack operations. - The stack symbols are the terminals and nonterminals of the grammar. - The designated starting stack symbol is the grammar start symbol. 3/20/

69 Transform a C-F grammar to empty-stack PDA: Basic idea: Use the stack of the PDA to simulate the (leftmost) derivation of a string in the grammar Push S (start symbol of CFG) on the stack From this point on, there are two moves the PDA can make: If a non-terminal A is on the top of the stack, it and push the right-hand side of a production A B1B2 Bn from G 2. If a terminal a is on the top of the stack, it and match it with whatever symbol is being read from the input string 3/20/

70 Leftmost and Rightmost Derivations Consider the grammar G = ({S, A, B, C}, {a, b, c}, S, P) where P = { S ABC, A aa Ʌ, B bb Ʌ, C cc Ʌ } Leftmost derivation (always expand the leftmost variable first): S ABC aabc abc abbc abbbc abbc abbcc abbc Rightmost derivation (always expand the rightmost variable first): S ABC ABcC ABc AbBc AbbBc Abbc aabbc abbc Note: 1. Different derivations result in different sentential forms, but 2. For a C-F grammar, it doesn't make difference in what order we expand the variables. 70

71 How to simulate a leftmost derivation of abbc for the grammar S ABC A aa B bb C cc S ABC aabc abc abbc abbbc abbc abbcc abbc S ABC A aa A Ʌ B bb B bb B Ʌ C cc C Ʌ 71

72 S ABC abbbc aabc abc abbc abbc abbcc abbc S ABC A aa A Ʌ B bb B bb B Ʌ C cc C Ʌ push S + push A B C + push a A B C A B C B C + push b B C 72 Output: a b

73 S ABC abbbc aabc abc abbc abbc abbcc abbc S ABC A aa A Ʌ B bb B bb B Ʌ C cc C Ʌ B C + push b B C B C C + push c C C 73 Output: a b b c

74 How to simulate a leftmost derivation of aaab for the grammar S asb aas S asb a( aas) b a( aa) b S asb ; S aas ; S Ʌ push S + push a S b S b + push a a S b a S b S b Output: a a a b 74 b

75 Transform a C-F grammar to empty-stack PDA: Algorithm: 1. For each terminal a, deterministic or non-deterministic? create instruction (0, a, a,, 0) a, a S 0 Why? 75

76 Algorithm: 1. For each terminal a, create instruction (0, a, a,, 0) S a, a 0 Why? A terminal a exists in a production of the form B a or B aw. Once B is replaced with a or aw, the stack looks like: 76 a or For a PDA, we need an instruction that can be used to remove a from the stack (to empty the stack): a, a a w

77 Transform a C-F grammar to empty-stack PDA: Algorithm: 2. For each production A B1B2 Bn create instruction (0, Ʌ, A,, push(bn),, push(b1), 0) Ʌ, A, push B n,, push (B 1 ) S 0 Why? 77

78 Algorithm: 2. For each production A B1B2 Bn create instruction (0, Ʌ, A,, push(bn),, push(b1), 0) Why do we know A would be in the stack? Because before this production, we would have a production like: S XAY Therefore, by executing (0, Ʌ, S, <, push(y), push(a), push(x)>, 0) S 78 X A Y

79 Transform a C-F grammar to empty-stack PDA: Algorithm: 3. For each production A Ʌ create instruction (0, Ʌ, A,, 0) Ʌ, A S 0 Why? 79

80 Transform a C-F grammar to empty-stack PDA: Algorithm: 3. For each production A Ʌ create instruction (0, Ʌ, A,, 0) Ʌ, A Why? The production A Ʌ is for us to terminate a derivation process. S 0 For a PDA, we need an instruction that can be used to empty a stack: Ʌ, A 80

81 Example. For the grammar: S Ʌ asb aas, do a leftmost derivation of aaab and show the IDs for executing it. First, get PDA instructions for terminals and productions: Terminals Corresponding PDA instructions a ( 0, a, a,, 0 ) b ( 0, b, b,, 0 ) Start with this one Productions Corresponding PDA instructions S asb (0,, S,, push( b), push( S), push( a), 0) S aas (0,, S,, push( S), push( a), push( a), 0) S (0,, S,, 81 0)

82 Example. For the grammar: S Ʌ asb aas, do a leftmost derivation of aaab and show the IDs for executing it. S a, a 0 Ʌ, S b, b Ʌ, S, push b, push S, push(a) Ʌ, S, push S, push a, push(a) 82

83 Example. For the grammar: S Ʌ asb aas, do a leftmost derivation of aaab and show the IDs for executing it. Leftmost derivation of aaab S asb a( aas) b a( aa) b 83

84 Example. For the grammar: S Ʌ asb aas, do a leftmost derivation of aaab and show the IDs for executing it. ID for aaab: PDA instruction: (0, aaab, S) (0, aaab, asb) (0, aab, Sb) (0, aab, aasb) (0, ab, asb) (0, b, Sb) (0, b, b) (0,, ) S aa a S b S ( 0,, S,, push( b), push( S), push( a) ( 0, a, a,, 0) ( 0,, S,, push( S), push( a), push( a) ( 0, a, a,, 0) ( 0, a, a,, 0) ( 0,, S,, 0) ( 0, b, b,, 0) 84 Accepted, 0), 0)

85 End of Context-Free Languages and Pushdown Automata I 85

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

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

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

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings 11-711: Algorithms for NLP October 10, 2014 Conversion to CNF Example grammar

More information

Lecture 11 Context-Free Languages

Lecture 11 Context-Free Languages Lecture 11 Context-Free Languages COT 4420 Theory of Computation Chapter 5 Context-Free Languages n { a b : n n { ww } 0} R Regular Languages a *b* ( a + b) * Example 1 G = ({S}, {a, b}, S, P) Derivations:

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

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

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

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

Automata Theory (2A) Young Won Lim 5/31/18

Automata Theory (2A) Young Won Lim 5/31/18 Automata Theory (2A) Copyright (c) 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

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

Chapter 5: Context-Free Languages

Chapter 5: Context-Free Languages Chapter 5: Context-Free Languages Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106 cappello@cs.ucsb.edu Please read the corresponding chapter

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

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF) CS5371 Theory of Computation Lecture 7: Automata Theory V (CFG, CFL, CNF) Announcement Homework 2 will be given soon (before Tue) Due date: Oct 31 (Tue), before class Midterm: Nov 3, (Fri), first hour

More information

Pushdown Automata (Pre Lecture)

Pushdown Automata (Pre Lecture) Pushdown Automata (Pre Lecture) Dr. Neil T. Dantam CSCI-561, Colorado School of Mines Fall 2017 Dantam (Mines CSCI-561) Pushdown Automata (Pre Lecture) Fall 2017 1 / 41 Outline Pushdown Automata Pushdown

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

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

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

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

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

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

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

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

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

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 algera, relations, functions) (read Chapters

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

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

Accept or reject. Stack

Accept or reject. Stack Pushdown Automata CS351 Just as a DFA was equivalent to a regular expression, we have a similar analogy for the context-free grammar. A pushdown automata (PDA) is equivalent in power to contextfree grammars.

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation CFL Hierarchy CFL Decision Problems Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Anything else I have included some slides online

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

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

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

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

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

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

Pushdown Automata: Introduction (2)

Pushdown Automata: Introduction (2) Pushdown Automata: Introduction Pushdown automaton (PDA) M = (K, Σ, Γ,, s, A) where K is a set of states Σ is an input alphabet Γ is a set of stack symbols s K is the start state A K is a set of accepting

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

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 (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

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

October 6, Equivalence of Pushdown Automata with Context-Free Gramm Equivalence of Pushdown Automata with Context-Free Grammar October 6, 2013 Motivation Motivation CFG and PDA are equivalent in power: a CFG generates a context-free language and a PDA recognizes a context-free

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

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

Miscellaneous. Closure Properties Decision Properties

Miscellaneous. Closure Properties Decision Properties Miscellaneous Closure Properties Decision Properties 1 Closure Properties of CFL s CFL s are closed under union, concatenation, and Kleene closure. Also, under reversal, homomorphisms and inverse homomorphisms.

More information

FLAC Context-Free Grammars

FLAC Context-Free Grammars FLAC Context-Free Grammars Klaus Sutner Carnegie Mellon Universality Fall 2017 1 Generating Languages Properties of CFLs Generation vs. Recognition 3 Turing machines can be used to check membership in

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

Context-Free Languages

Context-Free Languages CS:4330 Theory of Computation Spring 2018 Context-Free Languages Pushdown Automata Haniel Barbosa Readings for this lecture Chapter 2 of [Sipser 1996], 3rd edition. Section 2.2. Finite automaton 1 / 13

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

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

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

Push-down Automata = FA + Stack

Push-down Automata = FA + Stack Push-down Automata = FA + Stack PDA Definition A push-down automaton M is a tuple M = (Q,, Γ, δ, q0, F) where Q is a finite set of states is the input alphabet (of terminal symbols, terminals) Γ is the

More information

Part I: Definitions and Properties

Part I: Definitions and Properties Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States

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

Equivalence of CFG s and PDA s

Equivalence of CFG s and PDA s Equivalence of CFG s and PDA s Mridul Aanjaneya Stanford University July 24, 2012 Mridul Aanjaneya Automata Theory 1/ 53 Recap: Pushdown Automata A PDA is an automaton equivalent to the CFG in language-defining

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

6.8 The Post Correspondence Problem

6.8 The Post Correspondence Problem 6.8. THE POST CORRESPONDENCE PROBLEM 423 6.8 The Post Correspondence Problem The Post correspondence problem (due to Emil Post) is another undecidable problem that turns out to be a very helpful tool for

More information

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov

CMP 309: Automata Theory, Computability and Formal Languages. Adapted from the work of Andrej Bogdanov CMP 309: Automata Theory, Computability and Formal Languages Adapted from the work of Andrej Bogdanov Course outline Introduction to Automata Theory Finite Automata Deterministic Finite state automata

More information

Automata Theory - Quiz II (Solutions)

Automata Theory - Quiz II (Solutions) Automata Theory - Quiz II (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu} 1 Problems 1. Induction: Let L denote the language of balanced strings over Σ =

More information

Theory of Computation Lecture 1. Dr. Nahla Belal

Theory of Computation Lecture 1. Dr. Nahla Belal Theory of Computation Lecture 1 Dr. Nahla Belal Book The primary textbook is: Introduction to the Theory of Computation by Michael Sipser. Grading 10%: Weekly Homework. 30%: Two quizzes and one exam. 20%:

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

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

UNIT-VI PUSHDOWN AUTOMATA

UNIT-VI PUSHDOWN AUTOMATA Syllabus R09 Regulation UNIT-VI PUSHDOWN AUTOMATA The context free languages have a type of automaton that defined them. This automaton, called a pushdown automaton, is an extension of the nondeterministic

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

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm Testing Emptiness of a CFL As for regular languages, we really take a representation of some language and ask whether it represents φ Can use either CFG or PDA Our choice, since there are algorithms to

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

Equivalent Variations of Turing Machines

Equivalent Variations of Turing Machines Equivalent Variations of Turing Machines Nondeterministic TM = deterministic TM npda = pushdown automata with n stacks 2PDA = npda = TM for all n 2 Turing machines with n tapes (n 2) and n tape heads has

More information

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism, CS 54, Lecture 2: Finite Automata, Closure Properties Nondeterminism, Why so Many Models? Streaming Algorithms 0 42 Deterministic Finite Automata Anatomy of Deterministic Finite Automata transition: for

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

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

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

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack A pushdown automata (PDA) is essentially: An NFA with a stack A move of a PDA will depend upon Current state of the machine Current symbol being read in Current symbol popped off the top of the stack With

More information

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions CFG Simplification (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions 1 Eliminating useless symbols 1. A symbol X is generating if there exists: X * w, for

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 Design a PDA and a CFG for a given language Give informal description for a PDA,

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

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

Computational Models - Lecture 5 1

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

More information

MTH401A Theory of Computation. Lecture 17

MTH401A Theory of Computation. Lecture 17 MTH401A Theory of Computation Lecture 17 Chomsky Normal Form for CFG s Chomsky Normal Form for CFG s For every context free language, L, the language L {ε} has a grammar in which every production looks

More information

Pushdown Automata (PDA) The structure and the content of the lecture is based on

Pushdown Automata (PDA) The structure and the content of the lecture is based on Pushdown Automata (PDA) The structure and the content of the lecture is based on http://www.eecs.wsu.edu/~ananth/cpts317/lectures/index.htm 1 Excursion: Previous lecture n Context-free grammar G=(V,T,P,S),

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

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 3.3, 4.1 State and use the Church-Turing thesis. Give examples of decidable problems.

More information

HW 3 Solutions. Tommy November 27, 2012

HW 3 Solutions. Tommy November 27, 2012 HW 3 Solutions Tommy November 27, 2012 5.1.1 (a) Online solution: S 0S1 ɛ. (b) Similar to online solution: S AY XC A aa ɛ b ɛ C cc ɛ X axb aa b Y by c b cc (c) S X A A A V AV a V V b V a b X V V X V (d)

More information

UNIT-I. Strings, Alphabets, Language and Operations

UNIT-I. Strings, Alphabets, Language and Operations UNIT-I Strings, Alphabets, Language and Operations Strings of characters are fundamental building blocks in computer science. Alphabet is defined as a non empty finite set or nonempty set of symbols. The

More information

Computational Models - Lecture 4 1

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

More information

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced. Homework Context Free Languages PDAs and CFLs Homework #3 returned Homework #4 due today Homework #5 Pg 169 -- Exercise 4 Pg 183 -- Exercise 4c,e,i (use JFLAP) Pg 184 -- Exercise 10 Pg 184 -- Exercise

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

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

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

REGular and Context-Free Grammars

REGular and Context-Free Grammars REGular and Context-Free Grammars Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it March 26, 2018 1 Partly Based on Alessandro Barenghi s

More information

CISC 4090 Theory of Computation

CISC 4090 Theory of Computation CISC 4090 Theory of Computation Context-Free Languages and Push Down Automata Professor Daniel Leeds dleeds@fordham.edu JMH 332 Languages: Regular and Beyond Regular: Captured by Regular Operations a b

More information

Context Free Grammars

Context Free Grammars Automata and Formal Languages Context Free Grammars Sipser pages 101-111 Lecture 11 Tim Sheard 1 Formal Languages 1. Context free languages provide a convenient notation for recursive description of languages.

More information

Theory of Computer Science

Theory of Computer Science Theory of Computer Science C1. Formal Languages and Grammars Malte Helmert University of Basel March 14, 2016 Introduction Example: Propositional Formulas from the logic part: Definition (Syntax of Propositional

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

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F) Outline Nondeterminism Regular expressions Elementary reductions http://www.cs.caltech.edu/~cs20/a October 8, 2002 1 Determistic Finite Automata A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F) Q is a finite

More information

Nondeterministic Finite Automata

Nondeterministic Finite Automata Nondeterministic Finite Automata Not A DFA Does not have exactly one transition from every state on every symbol: Two transitions from q 0 on a No transition from q 1 (on either a or b) Though not a DFA,

More information

Solutions to Problem Set 3

Solutions to Problem Set 3 V22.0453-001 Theory of Computation October 8, 2003 TA: Nelly Fazio Solutions to Problem Set 3 Problem 1 We have seen that a grammar where all productions are of the form: A ab, A c (where A, B non-terminals,

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

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama

Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama Midterm Exam 2 CS 341: Foundations of Computer Science II Fall 2018, face-to-face day section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand

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

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