SFWR ENG 2FA3. Solution to the Assignment #4

Size: px
Start display at page:

Download "SFWR ENG 2FA3. Solution to the Assignment #4"

Transcription

1 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 have more than one solution. If you think your solution has been marked wrongly, write a short memo stating where marking in wrong and what you think is right, and resubmit to me during class, office hours, or just slip under the door to my office. 1.[20] (a)[2] In the left automaton the states 7,8 are not accessible, in the right automaton all states are accessible. (b)[10] Left automaton: x 3 x x 4 x x 5 x x x 6 x x x x 1

2 Hence the equivalence classes are {1,6},{2,5},{3,4}. Right automaton: x x 4 x x 5 x x x x 6 x x x x 7 x x x x 8 x x x x x Hence the equivalence classes are {1, 2},{3, 4, 8},{5, 6, 7}. (c)[8] Minimum state left automaton Minimum state right automaton 2.[16] Consider the following context-free grammar G: R XRX S S at b bta T XT X X ε X a b Answer the following questions: 1. [1] What are the variables/nonterminals of G? Answer: N = {R, X, S, T }. 2. [1] What are the terminals of G? Answer: Σ = {a,b}. 3. [1] What is the start variable of G? Answer: This is ambiguous question with two correct answers. One is S as most textbooks say that S denotes the start 2

3 symbol. The other is R as customarily the start symbol is usually the top right variable. Those who will take 3RA3 next term will hear more on the requirements ambiguity problem. 4. [1] Give three strings in L(G). Answer. If S is the start symbol: ab,ba,aab; if R is the start symbol: ab,ba,aab. 5. [1] Give three strings not in L(G). Answer. If S is the start symbol: a,b,ε; if R is the start symbol: a,b,ε. 6. [1] True or false: T aba. Answer: No. 7. [1] True or false: T aba. Answer: Yes, as T XT X at X axx abx aba. 8. [1] True or false: T T. Answer: Yes, as includes the identity relation. 9. [1] True or false: XXX aba. Answer: Yes, as XXX axx abx aba. 10. [1] True or false: X aba. Answer: No. 11. [1] True or false: T XX. Answer: Yes, as T XT X XX. 12. [1] True or false: T XXX. Answer: Yes, as T XT X XXX. 13. [1] True or false: S ε. Answer: No. 14. [3] Give a description in English of L(G). Answer: If S is the start symbol, R is useless symbol and L(G) is the set of all strings over a,b that have length bigger or equal 2, and the first symbol is always different than the last one. If R is the start symbol, L(G) consists of all strings over a,b that are not palindromes. 3.[10] Give context-free grammars generating the following languages: (a) [5] (b) [5] The set of strings over the alphabet {a,b} with more a s than b s. S TaT T T T at b bta a ε T generates all strings with at least as many a s as b s, and S forces an extra a. {a m b n c p d q m + n = p + q}. S asd A B A aac C B bbd C C bcc ε For all productions, we generate one a or b on left side, and one c or d on the right side, which can guarantee that m + n = p + q. Variable A cover cases that m q, while variable B cover cases that m q. 3

4 4.[10] Exercise 3 (page 306 of the Kozen textbook). The simplest and most straightforward grammar G is: S ε (S) [S] SS. We have to show that L(G) = PAREN 2. First we show that L(G) PAREN 2. The proof is by induction on the length of derivation. If S x, then x = ε PAREN 2. Suppose that for every x {(,),[,]} such that if S k x, where 1 k n, then x PAREN 2 (strong induction!). Consider the case S n+1 y, where x {(,),[,]}. We have two cases: S n v(s)w y = v()w, or S n v[s]w z = v[]w, where v,w {(,),[,]}, and S k v, S m w where k < n and m < n. Hence, by inductive assumption v,w PAREN 2. If v,w PAREN 2, then by (ii) and (iii) of the definition of PAREN 2, we immediately get v()w PAREN 2 and v[]w PAREN 2. This means L(G) PAREN 2. Now we have to show that PAREN 2 L(G). The proof by the inductive definition of PAREN 2. Clearly ε L(G) so we are done with (i) of the definition of PAREN 2. Let x L(G), i.e S x {(,),[,]}. Consider (x) and [x]. We have S (S) (x), so (x) L(G). Similarly S (S) [x], so [x] L(G). Hence we are done with (ii) of the definition of PAREN 2. Let x,y L(G), i.e S x {(,),[,]} and S y {(,),[,]}. In this case: S SS xs xy, so xy L(G). So we are done with (iii) of the definition of PAREN 2. Hence PAREN 2 L(G), i.e. L(G) = PAREN 2. 5.[5] Eliminate all useless productions from the below grammar. S a aa B C A ab ε B Aa C ccd D d What language does this grammar generate? Step 1. There is only one variable from which we cannot derive a sequence of terminals, namely: C After erasing it we get: S a aa B A ab ε B Aa D d 4

5 Step 2. There is only one variable that does not appear in any string derived from S, namely: D After erasing it we get: S a aa B A ab ε B Aa The grammar generates the language containing only odd number of a s, i.e. {a 2k+1 k 0}. 6.[5] Eliminate all ε-productions from the below grammar. S ABaC A BC B b ε C D ε D d In the first step we conclude that B, C can eventually generate ε (they are often called nullable). Then, since A BC we conclude that A can also generate ε. It is easy to observe that only A,B,C can generate ε. Hence: S ABaC BaC AaC ABa ac Ba Aa a A BC B C B b C D D d 7.[5] Eliminate all unit-productions from the below grammar. S Aa A a bc B B A bb We have A B and B A, so actually A is the same as B. Therefore we can change: A a bc B B A bb into just 5

6 A a bc bb Hence the final grammar is: S Aa A a bc bb 8.[10] Convert the below grammar into Chomsky Normal Form. S abab A bab ε B BAa A ε First we have to get rid of all ε-productions. The obtained grammar is: S abab aba abb ab A bab ba bb b B BAa Aa Ba a A Next we have to get rid of all unit-productions. The result is: S abab aba abb ab A bab ba bb b B BAa Aa Ba a bab ba bb b Now, we may produce a Chomsky normal form: S X a X bab X a X ba X a X bb X a X b X a a X b b X bab X a X AB X ba X b A X bb X b B X AB AB A X b X AB X b A X b B b B X BA X a AX a BX a a X b X AB X a A X b B b X BA BA 8a.[10] Convert the below grammar into Graibach Normal Form. S ABb a A aaa b B bab bbb ABB a 6

7 First substitute A by aaa b in B ABB. The result is B bab bbb a aaabb bbb, i.e. B bab bbb a aaabb. Now we substitute A by aaa b in S ABb. The result is S aaabb baab a Hence now we have: S aaabb baab a A aaa b B bab bbb a aaabb which is almost Graibach. We just need to add C a a, C b b, and replace a and b that are not first by C a and C b, respectively. Final result: S ac a ABC b baac b a A ac a A b B bac b bbb a ac a ABB C a a C b b 9.[10] Construct a pushdown automaton accepting: {a n b m 2n = 3m n 0 m 0} You can choose either acceptance with the empty stack of final state. The below solution has in fact both. Note that the language in question is {ε,a 3 b 2,a 6 b 4,...}, i.e. {a 3k b 2k k 0} Thus, for each symbol a of the input, we push two copies of symbol a into the stack (this is done when in state s). Then, for each symbol b we read from the input, we match it with three a s in the stack (using states q 1,q 2,q 3,q 4 ). The automaton looks as follows: M = (Q,Σ,Γ,δ,s,,F), where Q = {s,q 1,q 2,q 3,q 4,r}, Σ = {a,b}, Γ = {a,b, }, F = {r}, and the relation δ is the following: 7

8 {(s, ε, ),(r, ε), just to accept empty string (s,a, ),(s,aa ), first push of aa (s,a,a),(s,aa), remaining pushes of aa, note that for example aa on the input tape results in aaaa on the stack! (s,b,a),(q 1,ε), first encounter of b (q 1,ε,a),(q 2,ε), the remaining 3 steps deal with matching 3 a s with 2 b s (q 2,ε,a),(q 3,ε), (q 3,b,a),(q 4,ε), (q 4,b,a),(q 1,ε), (q 3,ε, ),(r,ε)} just to go to the final state 10.[10] Construct a pushdown automaton accepting: {a i b i c k i, j,k 0 i + k = j} You can choose either acceptance with the empty stack of final state. The below solution has in fact both. The basic idea for this problem is to use different states to enforce the order of the occurrences of the letters a,b and c, and use the stack to meet the requirement of i + k = j.the automaton looks as follows: M = (Q,Σ,Γ,δ,s,,F), where Q = {s,q, p,r}, Σ = {a,b,c}, Γ = {a,b,c, }, F = {r}, and the relation δ is the following: {(s,a, ),(s,a ), (s,b, ),(s,b ), (s,a,a),(s,aa), (s,b,a),(q,ε), (q,b,a),(q,ε), (q,b, ),(q,b ), (q,b,b),(p,bb), (p,c,b),(p,ε), (p,ε, ),(r,ε)} 11.[10] Show that the following language is not context-free: {a i b i2 i > 0} Assume L = {a n b i2 i > 0} is context free, then pumping lemma hold. Let p be the number in pumping lemma. We take z = a p2 b p. Clearly, z p and z L. Therefore, z = uvwxy and vx 1, vwx p, and for all i 0, uv i wx i y L. Let us consider two cases, Case 1. vx = a k, i.e. it contains no b. Then, z = uv 2 wx 2 y = a q+k b p, and k1. Therefore, z / L, a contradiction. 8

9 Case 2. vx = a j b k, and k1, i.e. it contains at least one b. Then, consider z = uv 0 wx 0 y. We have: # a (z ) = q j = p 2 j, and 1 j p 1 (# a (z ) is the number of a in z), and # b (z ) = p k, and 1 k p. So, (# b (z)) 2 = (p k) 2 = p 2 2kp + k 2. Clearly kp j > k 2 kp, because kp j p (p 1) = 1, and k 2 kp = k(k p) 0. Now, it is easy to verify that, p 2 j > p 2 2kp + k 2. Therefore, z / L, contradiction. 12.[10] Describe a Turing Machine that accept {a 2n n 0}. Solution. The idea is the following: for each input string w 1. Sweep left to right across the tape, crossing off every other a. 2. If in stage 1 the tape contained a single a, accept. 3. If in stage 1 the tape contained more than a single a and the number of a was odd, reject. 4. Return the head to the left-hand end of the tape. 5. Go to 1. The formal description could be the following: M = (Q,Σ,Γ,,,δ,q 1,q accept,q re ject ), where Q = (q 1,q 2,q 3,q 4,q 5,t,r) Σ = {a} Γ = {a,x,, } q 1 is the start state. and the δ is given by the below table δ a x q 1 (q 1,,R) (q 1,,R) (q re ject,,r) (q re ject,x,r) q 2 (q re ject,,r) (q 3,x,R) (q accept,,r) (q 2,x,R) q 3 (q re ject,,r) (q 4,a,R) (q 5,,L) (q 3,x,R) q 4 (q re ject,,r) (q 3,x,R) (q re ject,,r) (q 4,x,R) q 5 (q re ject,,r) (q 5,a,L) (q 2,,L) (q 5,x,L) 9

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

1.[3] Give an unambiguous grammar that generates the set of all regular expressions on Ó = {a,b}. Justify your construction.

1.[3] Give an unambiguous grammar that generates the set of all regular expressions on Ó = {a,b}. Justify your construction. CAS 705. Sample solutions to the assignment 2 (many questions have more than one solutions). Total of this assignment is 135 pts. Each assignment is worth 25%. 1.[3] Give an unambiguous grammar that generates

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

Solution to CS375 Homework Assignment 11 (40 points) Due date: 4/26/2017

Solution to CS375 Homework Assignment 11 (40 points) Due date: 4/26/2017 Solution to CS375 Homework Assignment 11 (40 points) Due date: 4/26/2017 1. Find a Greibach normal form for the following given grammar. (10 points) S bab A BAa a B bb Ʌ Solution: (1) Since S does not

More information

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3}, Code No: 07A50501 R07 Set No. 2 III B.Tech I Semester Examinations,MAY 2011 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 80 Answer any FIVE Questions All

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

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

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove Tuesday 28 of May 2013 Total: 60 points TMV027/DIT321 registration VT13 TMV026/DIT321 registration before VT13 Exam

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

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

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a.

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a. VTU QUESTION BANK Unit 1 Introduction to Finite Automata 1. Obtain DFAs to accept strings of a s and b s having exactly one a.(5m )( Dec-2014) 2. Obtain a DFA to accept strings of a s and b s having even

More information

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

Lecture 12 Simplification of Context-Free Grammars and Normal Forms Lecture 12 Simplification of Context-Free Grammars and Normal Forms COT 4420 Theory of Computation Chapter 6 Normal Forms for CFGs 1. Chomsky Normal Form CNF Productions of form A BC A, B, C V A a a T

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

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0, Introduction to Formal Language, Fall 2016 Due: 21-Apr-2016 (Thursday) Instructor: Prof. Wen-Guey Tzeng Homework 4 Solutions Scribe: Yi-Ruei Chen 1. Find context-free grammars for the language L = {a n

More information

HW6 Solutions. Micha l Dereziński. March 20, 2015

HW6 Solutions. Micha l Dereziński. March 20, 2015 HW6 Solutions Micha l Dereziński March 20, 2015 1 Exercise 5.5 (a) The PDA accepts odd-length strings whose middle symbol is a and whose other letters are as and bs. Its diagram is below. b, Z 0 /XZ 0

More information

This lecture covers Chapter 7 of HMU: Properties of CFLs

This lecture covers Chapter 7 of HMU: Properties of CFLs This lecture covers Chapter 7 of HMU: Properties of CFLs Chomsky Normal Form Pumping Lemma for CFs Closure Properties of CFLs Decision Properties of CFLs Additional Reading: Chapter 7 of HMU. Chomsky Normal

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

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

Context-Free Grammar

Context-Free Grammar Context-Free Grammar CFGs are more powerful than regular expressions. They are more powerful in the sense that whatever can be expressed using regular expressions can be expressed using context-free grammars,

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

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

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols Finite Automata and Formal Languages TMV026/DIT321 LP4 2012 Lecture 13 Ana Bove May 7th 2012 Overview of today s lecture: Normal Forms for Context-Free Languages Pumping Lemma for Context-Free Languages

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form:

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

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

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK 7 april 23 Classrum Edition CONTEXT FREE LANGUAGES & PUSH-DOWN AUTOMATA CONTEXT-FREE GRAMMARS, CFG Problems Sudkamp Problem. (3.2.) Which language generates the

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

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

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

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

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

CS A Term 2009: Foundations of Computer Science. Homework 2. By Li Feng, Shweta Srivastava, and Carolina Ruiz. CS3133 - A Term 2009: Foundations of Computer Science Prof. Carolina Ruiz Homework 2 WPI By Li Feng, Shweta Srivastava, and Carolina Ruiz Chapter 4 Problem 1: (10 Points) Exercise 4.3 Solution 1: S is

More information

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata. Code No: R09220504 R09 Set No. 2 II B.Tech II Semester Examinations,December-January, 2011-2012 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 75 Answer

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

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

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008 Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008 Name: ID #: This is a Close Book examination. Only an A4 cheating sheet belonging to you is acceptable. You can write your answers

More information

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y. CSE2001, Fall 2006 1 Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y. S 00S1 A - xay, where x = 2 y.

More information

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4 Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form: A BC A a S ε B and C aren t start variables a is

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata CMSC 330 Spring 2017 1 How do regular expressions work? What we ve learned What regular expressions are What they

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

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

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

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

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

Author: Vivek Kulkarni ( )

Author: Vivek Kulkarni ( ) Author: Vivek Kulkarni ( vivek_kulkarni@yahoo.com ) Chapter-3: Regular Expressions Solutions for Review Questions @ Oxford University Press 2013. All rights reserved. 1 Q.1 Define the following and give

More information

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-500 014 Subject: FORMAL LANGUAGES AND AUTOMATA THEORY Class : CSE II PART A (SHORT ANSWER QUESTIONS) UNIT- I 1 Explain transition diagram, transition

More information

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata

CMSC 330: Organization of Programming Languages. Regular Expressions and Finite Automata CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata CMSC330 Spring 2018 1 How do regular expressions work? What we ve learned What regular expressions are What they

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

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

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

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 Grammars: Normal Forms

Context-Free Grammars: Normal Forms Context-Free Grammars: Normal Forms Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr

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

Properties of context-free Languages

Properties of context-free Languages Properties of context-free Languages We simplify CFL s. Greibach Normal Form Chomsky Normal Form We prove pumping lemma for CFL s. We study closure properties and decision properties. Some of them remain,

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 14 Ana Bove May 14th 2018 Recap: Context-free Grammars Simplification of grammars: Elimination of ǫ-productions; Elimination of

More information

Theory of Computation

Theory of Computation Theory of Computation Lecture #2 Sarmad Abbasi Virtual University Sarmad Abbasi (Virtual University) Theory of Computation 1 / 1 Lecture 2: Overview Recall some basic definitions from Automata Theory.

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

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

Computability and Complexity

Computability and Complexity Computability and Complexity Rewriting Systems and Chomsky Grammars CAS 705 Ryszard Janicki Department of Computing and Software McMaster University Hamilton, Ontario, Canada janicki@mcmaster.ca Ryszard

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

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Notes for Comp 497 (Comp 454) Week 10 4/5/05 Notes for Comp 497 (Comp 454) Week 10 4/5/05 Today look at the last two chapters in Part II. Cohen presents some results concerning context-free languages (CFL) and regular languages (RL) also some decidability

More information

CS 373: Theory of Computation. Fall 2010

CS 373: Theory of Computation. Fall 2010 CS 373: Theory of Computation Gul Agha Mahesh Viswanathan Fall 2010 1 1 Normal Forms for CFG Normal Forms for Grammars It is typically easier to work with a context free language if given a CFG in a normal

More information

CSE 468, Fall 2006 Homework solutions 1

CSE 468, Fall 2006 Homework solutions 1 CSE 468, Fall 2006 Homework solutions 1 Homework 1 Problem 1. (a) To accept digit strings that contain 481: Q ={λ,4,48, 481}, Σ ={0,1,...,9}, q 0 = λ, A ={481}. To define δ, weuse a for all letters (well,

More information

In English, there are at least three different types of entities: letters, words, sentences.

In English, there are at least three different types of entities: letters, words, sentences. Chapter 2 Languages 2.1 Introduction In English, there are at least three different types of entities: letters, words, sentences. letters are from a finite alphabet { a, b, c,..., z } words are made up

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

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1)

COSE212: Programming Languages. Lecture 1 Inductive Definitions (1) COSE212: Programming Languages Lecture 1 Inductive Definitions (1) Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 1 September 4, 2017 1 / 9 Inductive Definitions Inductive definition (induction)

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

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University Simplification of CFG and Normal Forms Wen-Guey Tzeng Computer Science Department National Chiao Tung University Normal Forms We want a cfg with either Chomsky or Greibach normal form Chomsky normal form

More information

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University Simplification of CFG and Normal Forms Wen-Guey Tzeng Computer Science Department National Chiao Tung University Normal Forms We want a cfg with either Chomsky or Greibach normal form Chomsky normal form

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

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission. CSE 5 Homework Due: Monday October 9, 7 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 in this

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: a b c b d e a Not-regular: c n bd

More information

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1. Theory of Computer Science March 20, 2017 C1. Formal Languages and Grammars Theory of Computer Science C1. Formal Languages and Grammars Malte Helmert University of Basel March 20, 2017 C1.1 Introduction

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

Notes for Comp 497 (454) Week 10

Notes for Comp 497 (454) Week 10 Notes for Comp 497 (454) Week 10 Today we look at the last two chapters in Part II. Cohen presents some results concerning the two categories of language we have seen so far: Regular languages (RL). Context-free

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

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

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form Plan for 2 nd half Pumping Lemma for CFLs The Return of the Pumping Lemma Just when you thought it was safe Return of the Pumping Lemma Recall: With Regular Languages The Pumping Lemma showed that if a

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

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

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

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

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I Internal Examination 2017-18 B.Tech III Year VI Semester Sub: Theory of Computation (6CS3A) Time: 1 Hour 30 min. Max Marks: 40 Note: Attempt all three

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

Chap. 7 Properties of Context-free Languages

Chap. 7 Properties of Context-free Languages Chap. 7 Properties of Context-free Languages 7.1 Normal Forms for Context-free Grammars Context-free grammars A where A N, (N T). 0. Chomsky Normal Form A BC or A a except S where A, B, C N, a T. 1. Eliminating

More information

Please give details of your answer. A direct answer without explanation is not counted.

Please give details of your answer. A direct answer without explanation is not counted. Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to

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

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity.

I have read and understand all of the instructions below, and I will obey the University Code on Academic Integrity. Midterm Exam CS 341-451: Foundations of Computer Science II Fall 2016, elearning section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all

More information

Properties of Context-Free Languages

Properties of Context-Free Languages Properties of Context-Free Languages Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr

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

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

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

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

Ogden s Lemma. and Formal Languages. Automata Theory CS 573. The proof is similar but more fussy. than the proof of the PL4CFL.

Ogden s Lemma. and Formal Languages. Automata Theory CS 573. The proof is similar but more fussy. than the proof of the PL4CFL. CS 573 Automata Theory and Formal Languages Professor Leslie Lander Lecture # 24 December 4, 2000 Ogden s Lemma (6.2) Let L be a CFL, then there is a constant n such that if z is a word in L with z > n

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

CPSC 313 Introduction to Computability

CPSC 313 Introduction to Computability CPSC 313 Introduction to Computability Grammars in Chomsky Normal Form (Cont d) (Sipser, pages 109-111 (3 rd ed) and 107-109 (2 nd ed)) Renate Scheidler Fall 2018 Chomsky Normal Form A context-free grammar

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

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

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