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

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

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

Concordia University Department of Computer Science & Software Engineering

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

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

Theory of Computation - Module 3

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Theory of Computation

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CS375: Logic and Theory of Computing

Theory of Computation (Classroom Practice Booklet Solutions)

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

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

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

INSTITUTE OF AERONAUTICAL ENGINEERING

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

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.

Theory of Computation (IV) Yijia Chen Fudan University

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

Theory of Computer Science

Computational Models - Lecture 4

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

SFWR ENG 2FA3. Solution to the Assignment #4

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

The View Over The Horizon

CISC 4090 Theory of Computation

Computational Models - Lecture 4 1

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Homework 5 - Solution

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

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

Context-Free Grammar

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

Introduction to Theory of Computing

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

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

CS375: Logic and Theory of Computing

Context-Free Languages (Pre Lecture)

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computational Models - Lecture 5 1

CA320 - Computability & Complexity

The Pumping Lemma for Context Free Grammars

DM17. Beregnelighed. Jacob Aae Mikkelsen

Section 1 (closed-book) Total points 30

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

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

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

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

Formal Languages, Automata and Models of Computation

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

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

CS 420, Spring 2018 Homework 4 Solutions. 1. Use the Pumping Lemma to show that the following languages are not regular: (a) {0 2n 10 n n 0};

CISC 4090 Theory of Computation

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

Pushdown Automata. Reading: Chapter 6

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

Question Bank UNIT I

CS500 Homework #2 Solutions

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

CISC4090: Theory of Computation

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

CSE 355 Test 2, Fall 2016

Chapter 16: Non-Context-Free Languages

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

CPS 220 Theory of Computation

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

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

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

NPDA, CFG equivalence

SCHEME FOR INTERNAL ASSESSMENT TEST 3

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

Chapter 5: Context-Free Languages

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

Grammars and Context Free Languages

Computational Models - Lecture 3

Context-Free Grammars. 2IT70 Finite Automata and Process Theory

Let P(n) be a statement about a non-negative integer n. Then the principle of mathematical induction is that P(n) follows from

MA/CSSE 474 Theory of Computation

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CA320 - Computability & Complexity

Context-Free Grammars: Normal Forms

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

FLAC Context-Free Grammars

Automata Theory CS F-08 Context-Free Grammars

Foundations of Informatics: a Bridging Course

More Properties of Regular Languages

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

Grammars and Context Free Languages

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

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

Lecture 11 Context-Free Languages

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

MTH401A Theory of Computation. Lecture 17

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

CS 133 : Automata Theory and Computability

Transcription:

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) All strings with at least three a s aaa, aaa, aaa, aaaaa, aaa, aaa, aaa, aaa, aaa, aaa ) Write the grammar for the aove two languages i) All strings with no more than one a S B ii) S B BaB B B All strings with at least three a s BaBaBaB B ab 2. Give a simple description of the language generated y the grammar with production S aa A S S L = {(a) n : n>= 0 } 3. Find the grammar that generates the language L = {ww R : w {a, } + }. S aba B B B aba Format By : Mostafa Sayed (The Best) Page 2

4. Consider the grammar G = ({A, B, C, D, E, S}, {a}, S, P), with productions S ABaC Ba aab BC DC E ad Da AD AB ae Ea AE Drive three different sentences in L(G). From these, make a conjecture aout L(G). S S S aa, aaaa, aaaaaaaa. L(G) = {a n : n = 2 i, i>=} Format By : Mostafa Sayed (The Best) Page 3

Finite Automata Assignment. For = {a, }, construct dfa that accept the sets of a. All strings with no more than one a q 0 a q a q 2 a,. All strings with at least three a s a, q 0 a q a q 2 a q 3 2. Give a simple description of the language accepted y the following dfa a a, a q 0 q q 2 a q 3 All strings of a s and s except that contains sustring a 3. Find a dfa that accept the language defined y the following nfa q 0 q q 2 q 3 q 4 q 5 q 0 q q 2 q 3 q 4 q 5 4. Can you construct a dfa or nfa that accepts the following language L = {ww R : w {a, } + }. No: Explain why? Because it is not a regular language, it a context-free language. Format By : Mostafa Sayed (The Best) Page 4

5. For = {a, }, Convert the following nfa into an equivalent dfa. q 0 a q a, q 2 {q 0 } {q } a {q 2 } a, a {q, q 2 } Format By : Mostafa Sayed (The Best) Page 5

Regular Languages Assignment. Give a regular expression for a. L = {a n m, n >=4, m =< 3} aaaaa*(,,, ). L = {a n w, n >=3, w {a, } + } a*(a + )(a + )* 2. Find regular expression for the languages accepted y the following automata a. a*(a)** a a, a q 0 q q 2 a q 3. q 0 q q 2 q 3 + ()* q 4 q 5 3. Construct a dfa that accept the language generated y the grammar S aa A ab B aa a q 0 a q a q 2 q 3 a a, q 4 a, Format By : Mostafa Sayed (The Best) Page 6

4. Find a regular grammar for the language L = {a n m : n + m is even} S aaa aa A aaa B B B A aaa B 5. Show that there exits an algorithm for determining if L L 2 for any regular languages L and L 2 Since L and L 2 are regular languages, L U L 2 is also regular language. (Theorem 4.) If L U L 2 = L 2 then L L 2 We determine the aove equality using Theorem 4.7. Then, that there exits an algorithm for determining if L L 2 6. Consider the following languages. For each, state whether or not it is regular. Then prove your statement. a. L = {a n m, n =< m } This is not a regular language. To show that we need to use pumping lemma - The opponent: Given a positive integer m 2- We: choose w = aaaa a m m 3- The opponent: has to decompose w into xyz, xy < m a. xy contains all a s, y has at least one a,. xy contains all s, y has at least one, c. xy contains some a s and some s, y has a s and s, y i, i > 2, w does not elong to the language. d. xy contains some a s and some s, y has at least one, y i, i =0, we have a s more than s 4- We: show a. y i, i > 2, we have a s more than s. y i, i =0, we have a s more than s c. y i, i > 2, w does not elong to the language. d. y i, i =0, we have a s more than s Therefore, the language is not regular. Format By : Mostafa Sayed (The Best) Page 7

. L = {ww, w {a, } * } This is not a regular language. To show that we need to use pumping lemma - The opponent: Given a positive integer m 2- We: choose w = = aaaa a aaaa a m m m m 3- The opponent: has to decompose w into xyz, xy < m a. xy contains all a s, y has at least one a,. xy contains all s, y has at least one, c. xy contains some a s and some s, y has a s and s, d. xy contains some a s and some s, y has at least one, e. So on 4- We: show a. yi, i > 2, we have a s in the left more than a s in the right. yi, i > 2, we have s in the left more than s in the right c. y i, i =0, we have a s more than s d. y i, i > 2, w does not elong to the language. e. y i, i =0, we have s in the left more than s in the right f. So on Therefore, the language is not regular. c. L = {a n m c l, n + m + l = 0} This language is regular, since it is finite. d. L = {a n m : n + m is even} This language is regular; there is a regular grammar for it (see prolem 4). e. L = {a n m c l, n =< 0, m =< 0, l >= 0} This language is regular; there is a regular expression for it: (, a, aa, aaa, aaaa, aaaaaaaaaa)(,,,, )ccccccccccc* Format By : Mostafa Sayed (The Best) Page 8

Context-Free Language Assignment 7. Find context-free grammar for the following languages (n >= 0, m>=0, k>=0) a. L = {a n m, n =< m } S as B, B B. L = {ww, w {a,, c} * } This language is not a context-free language. We cannot write context-free grammar for it. c. L = {a n m c k, k = n + m } S asc abc, B Bc. 8. Show a derivation tree for the string aa with the grammar S AB, A ab, B S. S AB abb asb aabb aabbb aasbb aabb aasb aab aas aa 9. Show that the following grammar is amiguous S ass SaS S ass asass aass aas aa S ass as aass aas aa Format By : Mostafa Sayed (The Best) Page 9

Simplification of CFG Assignment 0. Eliminate all useless productions from the grammar S a aa B C, A ab, B Aa, C ccd, D ddd S a aa B A ab, B Aa. Eliminate -productions from the grammar S AaB aab, A, B A S ab aab a aa B 2. Transform the grammar S aab, A AB, B Baa A into Chomsky normal form. a. Eliminate -productions S aab aa ab a A A B AB B Baa A aa.. Eliminate unit productions B A S aab aa ab a A A B AB B Baa A B AB aa. c. Sustitute terminals symols with variales V a a V S V a V AB V a V A V a V B V a V A V A V B V AB B B V a V a V A V B V AB V a V a d. Simplify several variales into two variales V d V a V V e V a V a V f AB S V d V f Vd A V d B V a V A V A V B V V f B B V e V A V B V V f V a V a V a a V Format By : Mostafa Sayed (The Best) Page 0

Pushdown Automata. Construct and draw an npda that accept the following languages: a. L = L(a**) a,z/z,z/z q 0,z/z q,z/z q f We do not need to use the stack for this prolem. We need to have two different state for accepting a s and s. L = {a n m c m+n : n >= 0, m >= 0} a,z/0z,0/00 c,0/ a,0/00 q 0 q q 2 q f,0/00 c,0/,z/z a,z/0z a,0/00 c,/ c,0/,0/0,/ q 0 c,/ c,0/ q q f,z/z In the first solution, we are using a single stack symol with two states for accepting a s then s. In the second solution, we are using two different stack symols for accepting a s and s. But, we are using one state to accept oth of them. c. L = {a 3n n : n >= 0 } a,z/z a,3/3,3/ a,/2 a,2/3 q 0,3/ q,z/z q f We may use ant three symols to keep track of every three a s. (e.g. x,y,z) We may use just one symol and keep adding it. But we need to remove three symols for each. 2. Construct and draw an npda that accept the following languages: S BB, B SB a Convert this grammar to Greiach normal form: S ab BB B B abb a a,s/b,s/bb,s/ a,b/bb,b/b a,b/ q 0,z/Sz q,z/ q f Format By : Mostafa Sayed (The Best) Page

3. Show that the following language is not a context-free language L = {w {a,, c}* : n a (w) + n (w) = 2n c (w)} We need to use pumping lemma for context-free languages - The opponent: Given a positive integer m 2- We: choose w = aaaa a cccc c m m 2m 3- The opponent: has to decompose w into uvxyz, vxy =< m, vy >= e. vxy contains all a s, v and y has at least one a, f. vxy contains all s, v and y has at least one, g. vxy contains some a s and some s, v at least one a and y has at least one h. so on 4- We: show i. uv i xy i z, i > 2, we have a s more than c s j. uv i xy i z, i > 2, we have s more than c s k. uv i xy i z, i > 2, we have a s and s more than c s l. so on Therefore, the language is not a context-free language. Format By : Mostafa Sayed (The Best) Page 2

Turing Machine. Construct Turing machines that accepts the following language on {x, y, z}. a. L = {w: w is multiple of 4} (Draw the transition diagram). z/z,r y/y,r x/x,r c,0/ x/x,r x/x,r x/x,r q 0 y/y,r q y/y,r q 2 y/y,r q 3 z/z,r z/z,r z/z,r /,L q f. L = {w: n x (w) = n y (w) = n z (w)} (Draw the transition diagram). /,R y/y,r a/a,r c/c,r x/x,r /,R x/x,r /,R c/c,r a/a,r y/,r q x q xy x/a,r z/c,r c/c,r a/a,r x/a,r c/c,r a/a,r c/c,r a/a,r /,R c/c,l a/a,l /,L /,R /,R y/y,r y/y,r z/z,r x/x,l y/y,l z/z,l y/,r z/c,r q q y q yz x/a,r q xyz z/c,r y/,r /,R z/z,r x/a,r x/a,r /,R c/c,r a/a,r q f q xz /,R c/c,r a/a,r z/z,r x/x,r 2. Construct Turing machines that computes f(x, y) = 3x + y (Draw the transition diagram). Format By : Mostafa Sayed (The Best) Page 3

3. Construct Linear ounded automata for L = {ww R : w {a,, c} + } (Draw the transition diagram). c/c,l a/a,l /,L c/c,r a/a,r /,R q a ]/],L 0/0,L q aa a/0,r /,R a/0,l 0/0,R c/c,r a/a,r q 0 /0,R q ]/],L 0/0,L q /0,L q 2 ]/],L c/c,r a/a,r c/0,l c/0,r /,R ]/],L 0/0,L q c q c q Format By : Mostafa Sayed (The Best) Page 4

A Hierarchy of Formal Languages ) Give language examples that demonstrate the suset relations in the following diagram. These examples should e mutual exclusive (i.e. a CSL should not e CFL nor RL). RE Language CSL CFL RL a) R.E. Language: ) CSL: a n n c n c) CFL: a n n d) RL: a* 2) Find a PC-solution for the following sequences: X = { a, aa,, a } and Y = {, a, aa, a }. X2 X3 X X4 aa a a a aa a Y2 Y3 Y Y4 Format By : Mostafa Sayed (The Best) Page 5