AUBER (Models of Computation, Languages and Automata) EXERCISES

Similar documents
JNTUWORLD. Code No: R

UNIT I PART A PART B

Multiple Choice Questions

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table.


(a) R=01[((10)*+111)*+0]*1 (b) ((01+10)*00)*. [8+8] 4. (a) Find the left most and right most derivations for the word abba in the grammar

Compiler Construction

QUESTION BANK. Unit 1. Introduction to Finite Automata

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA?

1. Which of the following regular expressions over {0, 1} denotes the set of all strings not containing 100 as a sub-string?

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

CMSC 330, Fall 2009, Practice Problem 3 Solutions

CpSc 421 Final Solutions

1. [5 points each] True or False. If the question is currently open, write O or Open.

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

AUTOMATA THEORY AND COMPUTABILITY

Decision Properties for Context-free Languages

Theory of Computation, Homework 3 Sample Solution

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG)

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

CMSC 330 Practice Problem 4 Solutions

CT32 COMPUTER NETWORKS DEC 2015

Learn Smart and Grow with world

Theory Bridge Exam Example Questions Version of June 6, 2008

CS210 THEORY OF COMPUTATION QUESTION BANK PART -A UNIT- I

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007.

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5

DVA337 HT17 - LECTURE 4. Languages and regular expressions

Ambiguous Grammars and Compactification

CS402 - Theory of Automata Glossary By

Theory of Computation

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course)

CS402 - Theory of Automata FAQs By

CS/B.Tech/CSE/IT/EVEN/SEM-4/CS-402/ ItIauIafIaAblll~AladUnrtel1ity

Regular Languages (14 points) Solution: Problem 1 (6 points) Minimize the following automaton M. Show that the resulting DFA is minimal.

Answer All Questions. All Questions Carry Equal Marks. Time: 20 Min. Marks: 10.

CS 44 Exam #2 February 14, 2001

Automata Theory CS S-FR Final Review

Limitations of Algorithmic Solvability In this Chapter we investigate the power of algorithms to solve problems Some can be solved algorithmically and

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Theory of Computations Spring 2016 Practice Final

Decidable Problems. We examine the problems for which there is an algorithm.

Context-Free Grammars

Glynda, the good witch of the North

CSE 105 THEORY OF COMPUTATION

R10 SET a) Explain the Architecture of 8085 Microprocessor? b) Explain instruction set Architecture Design?

LECTURE NOTES THEORY OF COMPUTATION

Chapter Seven: Regular Expressions

The Turing Machine. Unsolvable Problems. Undecidability. The Church-Turing Thesis (1936) Decision Problem. Decision Problems

LECTURE NOTES THEORY OF COMPUTATION

1. Provide two valid strings in the languages described by each of the following regular expressions, with alphabet Σ = {0,1,2}.

SECTION A. (i) The Boolean function in sum of products form where K-map is given below (figure) is:

To illustrate what is intended the following are three write ups by students. Diagonalization

The CYK Algorithm. We present now an algorithm to decide if w L(G), assuming G to be in Chomsky Normal Form.

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

Theory of Computations Spring 2016 Practice Final Exam Solutions

Name: Finite Automata

From Theorem 8.5, page 223, we have that the intersection of a context-free language with a regular language is context-free. Therefore, the language

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

ROEVER COLLEGE OF ENGINEERING AND TECHNOLOGY Elambalur, Perambalur DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-I AUTOMATA

Computation Engineering Applied Automata Theory and Logic. Ganesh Gopalakrishnan University of Utah. ^J Springer

Context Free Languages and Pushdown Automata

ECS 120 Lesson 16 Turing Machines, Pt. 2

Formal languages and computation models

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Turing Machine Languages

CS525 Winter 2012 \ Class Assignment #2 Preparation

CIT3130: Theory of Computation. Regular languages

Languages and Compilers

UNIT 1 SNS COLLEGE OF ENGINEERING

CSE 105 THEORY OF COMPUTATION

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

Computer Sciences Department

Actually talking about Turing machines this time

Formal Languages and Automata

Final Course Review. Reading: Chapters 1-9

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees

Lec-5-HW-1, TM basics

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

Automating Construction of Lexers

TAFL 1 (ECS-403) Unit- V. 5.1 Turing Machine. 5.2 TM as computer of Integer Function

Formal Grammars and Abstract Machines. Sahar Al Seesi

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Outline. Language Hierarchy

Homework. Context Free Languages. Before We Start. Announcements. Plan for today. Languages. Any questions? Recall. 1st half. 2nd half.

1.3 Functions and Equivalence Relations 1.4 Languages

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

CS154 Midterm Examination. May 4, 2010, 2:15-3:30PM

CSC-461 Exam #2 April 16, 2014

Recursively Defined Functions

Regular Languages and Regular Expressions

Languages and Finite Automata

KEY. A 1. The action of a grammar when a derivation can be found for a sentence. Y 2. program written in a High Level Language

Transcription:

AUBER (Models of Computation, Languages and Automata) EXERCISES Xavier Vera, 2002

Languages and alphabets 1.1 Let be an alphabet, and λ the empty string over. (i) Is λ in? (ii) Is it true that λλλ=λ? Is it true for λ i, i 2? (iii) Let x and y be two strings over. Is the concatenation of x and y always equal to the concatenation of y and x? Describe when this situation holds. 1.2 A string is infinite when its length is infinite. Let be an alphabet. Does * contain any infinite string? If we change the restriction that makes finite, and let it be infinite, does it change the answer? 1.3 Let x, y and z be three strings over alphabet. Prove that xy concatenated with z is always the same as concatenating x with yz; this is, that concatenation is associative. 1.4 For a string x, x R is the same string read backward. Prove that (xy) R =y R x R, for any x y over. (hint: try to define x R inductively) 1.5 Prove: (i) (ii) (iii) There is no string x over {a,b} * such that ax=xb. If x is in {a,b} * and abx=xab, then there exists n such that x=(ab) n If w is a prefix of y and x is a prefix of yz, then either w is a prefix of x or x is a prefix of w. 1.6 Let u, v, w, z be strings over * such that uv=wz. Prove that there exists y in * such that: either uy=w and v=yz, or u=wy and yv=z 1.7 Let L i in *, i=1,2,3, be three languages. Are the following claims true? (i) (L 1 L 2 )L 3 =L 1 (L 2 L 3 ) (ii) (L 1 L 2 )L 3 =L 1 L 3 L 2 L 3 (iii) L 1 (L 2 L 3 )=L 1 L 2 L 1 L 3 (iv) (L 1 L 2 )L 3 =L 1 L 3 L 2 L 3 (v) L 1 (L 2 L 3 )=L 1 L 2 L 1 L 3 (vi) (L C ) C =L (vii) (L C ) * =(L * ) C (viii) (L 1 L 2 ) * =(L * 1 L * 2 ) * (ix) (L 1 L 2 L 1 ) * =L 1 (L 2 L 1 L 1 ) * 2

(x) (L 1 L 2 L 1 )*=L 1 (L 2 L 1 L 2 ) * (xi) (L * 1 ) * * =L 1 (xii) (L 1 L 2 ) * L 1 =L 1 (L 2 L 1 ) * * (xiii) L 1 =L 1 (xiv) (L 1 L 2 ) * =L * * 1 L 2 (xv) (L + 1 ) * =(L * 1 ) + (xvi) (L + 1 ) * * =L 1 (xvii) L + 1 L + + 1 =L 1 (xviii) (Ø) + =(Ø) * In case the claims are false in the general case, try to describe in which particular situations they are true. 1.8 Give examples of strings that belong and those that do not belong to the following languages defined over {a,b}: (i) (ii) (iii) (iv) {w u (w=uu R u)} {w ww=www} {w u,v (uvw=wvu)} {w u (uu=www)} 1.9 Give formal expressions for the following languages over {0,1}: (i) Strings that contain 000 but do not contain 001 (ii) Strings with at least one substring with length 3 which appears 3 or more times. (iii) Strings which none prefix represents, in binary, a multiple of 3. (iv) Strings with even length which codify an odd number. (v) Strings which has one prefix with more 0 s than 1 s. (vi) Strings with one suffix which is palindrome and length 3 (vii) Strings with a suffix equal to a prefix. (viii) Strings that if start with 00, do not concatenate 11. (ix) Strings that do not contain 000 and 111 at the same time. (x) Strings we can concatenate another string to in order to get a palindrome string. (xi) Strings with a substring that codify a prime number larger than 5. (xii) Strings which contain a number of 1 s multiple of 3. 1.10 Let ={a,b,c} and L={c i xc j : i,j 0, x=λ or x=aw or x=wb, w * }. Is L= *? Is L 2 = *? 3

Finite Automata 2.1 We are living in a building with 6 floors, and a new elevator is being installed. Since your mum is telling everyone that you are studying computer science, the board asks you to design the system that controls the decisions of the elevator. 2.2 Let M be the following DFA (i) Write down four strings accepted by M and the sequence of configurations that prove it (ii) Write down four strings that are not accepted by M. 2.3 Which are the languages accepted by the following automata? 4

2.4 Let M be the following NFA: (i) Write down four strings accepted by M and the sequence of configurations that prove it (ii) Write down four strings that are not accepted by M. 2.5 Prove that the following automata accepts the language L={a i b j, a i c j : i,j 1}. 2.6 Give DFA s that accept the following languages: (i) Strings over {a,b} that end in aa. (ii) Strings over {a,b} with three consecutive a s. (iii) Strings over {a,b} that do not contain the string aaa. (iv) The set of all the strings over {a,b} such that each string of length 5 contains at least two a s. (v) The set of all the strings over {a,b} such that the fifth symbol from the right is a b. (vi) The strings over {a,b} that have a pair of a s separated by a string of length 4i, i 0. (vii) The set of all the strings over {a,b} where all pairs of a s are just before a pair of b s. (viii) Strings λ, 001 and 000101. (ix) Strings over {0,1} that starts with 1 and that interpreted as binary numbers are 0 mod 5. (x) {w {a,b} * : w a =2n, w b =2m, m, n N} 5

(xi) {w {a,b} * : w =3n, n N and w does not contain aba} 2.7 Describe algorithms that decide: (i) (ii) (iii) (iv) whether two automata M and M accept the same language if an automata accepts, at least, one string if an automata accepts the language which contains all strings with odd length whether an automata accepts a cofinite language. 6

Regular Languages 3.1 Let E be the following regular expression: (i) Is L(E)={a,b,c} *? (ii) Is L(EE)={a,b,c} *? c * (λ+a(a+b+c) * +(a+b+c) * b)c * 3.2 Build regular expressions that are equivalent to the following languages over {a,b,c} of the strings that fulfill the following conditions: (i) there is an even number of a s in w, (ii) there are 4i+1 b s in w, i 0 (iii) w =3i, i 0 (iv) string abc does not appear in w. 3.3 A regular expression is ambiguous when there is a string that can be obtained following two different ways. Which regular expressions are ambiguous? (i) a((ab) * cd) * +a(ababcb * ) * a * (ii) aab * (ab) * +ab * +a * bba * (iii) aaba * +aaaba+aabba * +a 3.4 Build DFAs that recognize the languages defined by the regular expressions: (i) a * ba * ab * (ii) b((aab * +a 4 )b) * a (iii) ab[((ba) * +bbb) * +a] * b 3.5 Say whether the following equalities are true or false, where r, s and t are regular expressions. (r=s means, L(r)=L(s)) (i) r(sr) * =(rs) * r (ii) (r * s) * r * =(r+s) * (iii) (rs+r) * r=r(sr+r) * (iv) s(rs+s) * r=rr * s(rr * s) * (v) (r+s) * =r * +s * (vi) (λ+(0+1) * 100)0 * =λ+0+(0+1) * 00 (vii) (λ+1)0 * (1+110 * ) * =1 * (0+11+111) * 1 * (viii) (1+011+0011) * 0(0+1+01)0(0+1) * =(0+1) * 0(0+1)0(0+1) * 3.6 Build regular expressions equivalent to the following DFA s: 7

3.7 Find regular expressions for the DFAs defined in exercises 2.3 and 2.6. 3.8 Build a DFA equivalent to the regular expression: (00+(1+01)(11+0) * 10) * 3.9 Obtain the regular expression for the following automata and simplify it until you get (11+10+0) * 100 * 3.10 Is it true that if a language is the union of non-regular languages, it can not be regular? What about intersection? And concatenation? If it is true, prove it. Otherwise, give counterexamples. 3.11 Prove that the following languages are not regular: (i) {0 m 1 n 0 m+n : m,n 1} (ii) {ww: w (0+1) + } (iii) {(01) n (10) n : n 0} (iv) The set of all the strings over {0,1} with the same number of 1 s and 0 s. (v) {w (0+1) * : w=w R } (vi) {xx R w: x,w (0+1) + } (vii) {0 n : n is prime} (viii) {0 n : n is compound} 8

(ix) {0 m 1 n : m n} (x) {0 m 1 n : (m,n)=1} (m,n) is the gcd 3.12 Let L, defined over {0,1}, the set of the strings that interpreted as a number in binary are multiple of 3. Prove that L=L R. 3.13 Prove that if L is regular, L R is regular. 9

Grammars Consider the following languages: (i) The set of lists with compensated parenthesis, this is, where each left parenthesis has its right parenthesis, and they are correctly nested. (ii) The set of all strings over alphabet {a,b,.,*,(,),λ, } which are regular expressions over {a,b}. We should distinguish between λ as the empty string and λ as a symbol in the regular expression, which we denote as. (iii) {w (a+b) * :w=w R } (iv) {ww R :w (0+1) * } (v) The set {w#w R #:w (0+1) + } * (vi) The language of such strings over {a,b} such that each prefix has at least the same number of a s as b s. (vii) {a i b i c j d j :i,j 1} (viii) {a i b j b i a j :i,j 0} (ix) {0 m 1 n :m>n 0} (x) {a i b j c k :i j or j k} (xi) {0 k 1 m 0 n :n=k+m} (xii) {a n b m :1 n 2m} (xiii) {0 i 1 j 2 k :i=j or j=k} (xiv) {0 n 1 m :m=n or m=2n} (xv) {0 n 1 m :m n 2m} (xvi) The set of all strings over {0,1} with the same number of 0 as 1. (xvii) The set of all strings over {a,b} that have double numbers of a s as b s. (xviii) a * c * b * +(a * d) * cb * (xix) a * ba * ab * (xx) a((ab) * cb * ) * +a(ababcb * ) * a * (xxi) (a+b+c) * -{a k b k c k :k>0} 4.1 Give CFGs that generate the previous languages 4.2 Prove that the previous grammars actually generate those languages 4.3 Let G be a CFG with m variables, whose productions do not have a right side with length larger than k. Prove that if A * λ, there is a derivation of (km-1)/(k-1) steps at most from A to λ. Is possible to improve this lower bound? 4.4 Prove that for each grammar G there is a constant c such that if w L(G) and w λ, then w has a derivation with at most c w steps. 4.5 A grammar is right linear if all its productions have the following shape, either X wy or X v, where w and v belong to * and X and Y are variables. Prove that for all right linear grammars there is another equivalent one which has all the productions such as X ay or X λ, where a belongs to. 4.6 Simplify and transform all grammars from ex. 4.1 to Chomsky Form. 10

4.7 Let L 1 and L 2 two CFLs. Prove that: is a CFL. U n 1 ( L 1 ) n n ( L2 ) 4.8 Prove that the following grammar: S abs abs bas λ A baa a B abb b (i) (ii) It generates the language of all strings with the same number of a s as b s. It is not ambiguous. 4.9 Prove that for all languages L, L is CFL iff L R is CFL. 11

Pushdown Automata (PDA) 5.1 Give deterministic pushdown automata for the following languages: (i) {a 2i cb i :i 0} (ii) {a 2i+1 b i :i 0} (iii) {xcx R :x (a+b) * } (iv) {x:x (a+b) * and x a = x b } (v) The languages 1, 6, 7, 9, 11, 12 and 17 proposed in previous chapter. 5.2 Justify via pushdown automata that the following languages are not CFL: (i) {a i b j c k :i<j<k} (ii) {w (a+b+c) * : w a = w b = w c } (iii) {a n b n c m :n m 2n} (iv) {a i b j c k :i j k i} (v) {a i b j c k :i j k} (vi) {a i b j c i d j :i,j>0} (vii) {ww:w (a+b) * } (viii) {a i b j a k :k=max(i,k)} 5.3 Prove via the pumping lemma that languages from exercise 5.2 are not CFL. 12

Turing Machines 6.1 Design a Turing Machine that accepts the following languages over ={a,b} (i) {aba n b n 0} (ii) {w w is even} (iii) {a n b m n 1 and m n} (iv) {w w a = w b } (v) {a n b m a n+m n 0, m 1} (vi) {a n b n a n b m n 0, m 0} (vii) {a n b 2n n 1} (viii) {ww w {a,b} * } (ix) {w w=w R } (x) Set of strings over {(,)} that have balanced parenthesis 6.2 Build a TM which computes the parity function of the natural numbers: f(n)= 0 if n is even 1 if n is odd 6.3 Design a copy machine C. C transforms bwb to b3wb (b is the blank symbol) 6.4 Build a TM that computes f(n,m)=nm 6.5 Build a TM that computes f(n,m)=n-m, for n,m Naturals. How do you cope with n-m<0? 6.6 Build a TM such that: (i) Computes the integer function f(n)= floor(n/2) (ii) Given a string w and an integer n w, moves the reader/writer to the n- th symbol of w (iii) Adds two binary numbers (iv) Generate the complementary of a binary number (v) Shifts a binary number to the left, inserting 0. 13

Decidability 7.1 Classify the following problems as recursive, e.r or non of them. (i) A={x x,y f x (y)=z} (ii) A={x y f x (y)=y} (iii) A={x f x (x)=x} (iv) A={x Dom(f x ) is recursive} (v) A={x Dom(f x ) is not recursive} (vi) A={x Im(f x ) is recursive} (vii) A={x Im(f x ) is not recursive} (viii) A={x Dom(f x ) is e.r} (ix) A={x Dom(f x ) is recursive} 7.2 Let f be a decidable function. Let N(f)={x f(x)=0}. Prove that N(f) is e.r but it can t be recursive. 7.3 Classify the following languages/problems as recursive, e.r or non of them. (i) A={<x,y,z,t> M x (y)=z in t or less steps} (ii) A={<x,y,z,t> M x (y)=z in more than t steps} (iii) A={x z M x with input z halts in z steps} (iv) A={<x,y,z,t> M x (t)=m y (t)=m z (t)} (v) A={x f x =Id} (vi) A={x f x (2000) and f x (1000) } (vii) A={x y x f x =f y } (viii) A={<x,y> fx(y) or ( z x f x (y)=f z (y))} 7.4 Consider the problem of testing whether a Turing machine M on input w ever attempts to move its head left when its head is on the left-most tape cell. Formulate this problem as a language and show that it is undecidable. 7.5 A common operation in Turing-machine programs involves shifting over. We need to move the contents of each of the cells to the right of the current head position one cell right, and then find our way back to the current head position. (a) (b) Give the high level description of how to perform this operation. Hint: Leave a special symbol to mark the position to which the head must return. Design a Turing machine that shifts the entire input string one cell to the right. In this part, you are to give the formal description of the machine (you can draw the state diagram, or provide the delta function for the entire domain). Precisely, you will design a Turing machine M such that, given an input string w {0,1}*, M s accepting configuration will be q accept #w. 14

Recursive Functions 8.1 Write a recursive function that decides whether a number is a perfect square. 8.2 Write a recursive definition of the factorial of a natural number. 8.3 Write the following function in a recursive fashion: even(n)= 0 if n is even, 1 otherwise. 15

Unsorted Exercises 1. Given the following automata, which is minimal, prove that it accepts the language of all the strings over {0,1} * which length is odd and that do not ever have the same symbol in consecutive positions. 2. Prove that the language of the strings over {0,1} * that do not have the substring 010, is the same as L(E), where E is 1 * (0+11+111) * 1 * 3. Prove that L={w {0,1}* u www=uu} is not regular. 4. Let R be the language over {a,b} accepted by the following automata. Give a CFG that accepts the language L over {a,b,#} defined by: L={x#y x,y {a,b} * x = y x R} 16

5. Let L 1 and L 2 be the languages represented by the following automata. Give the minimal DFA that represents L1 L2. 6. Determinize the following automata. 7. Which is the DFA that represents the following language: L=L C a? 8. Let L be a regular language. What can we say about the following language L 1 ={w ww R ww R L}? 9. Which of the following languages are regular? {a n b m n>m n<m} {a n b m n m n m} {a n b m n>m n<m} {a n b m n m n m} 10. How many states do we need to describe the following language, L ij ={a k k is a multiple of i or j}? HINT: Make some particular cases. 11. What can you say about L={w {a,b}* abw=wba}? Is it the empty set? Is it regular? 12. Build the minimal DFA that recognizes the strings w over {a,b}, such that their length is larger than 4 and all the prefixes of length equal to 4 have the same number of a as b. (11 states) 13. Build the minimal DFA equivalent to the following regular expression: ((a+b)*+c)(ac)*b+a (8 states) 17

14. We say that x is a root of w if n 0 such that w=x n. Then, we define the root of a language L as root(l)={x n 0 x n L}. Prove that for any language L * : λ L <=> * =root(l) 18