Class Test-2 TAFL (NCS-402) Solution Section-A Q1. Prove or disprove the following for regular expressions r, s and t: (r + s)* = r* + s* Replace r by {a} and s by {b}. The left side becomes all strings of a's and b's (mixed), while the right side consists only of strings of a's (alone) and strings of b's (alone). A string like ab is in the language of the left side but not the right. Q2. Using Pumping Lemma, prove that L = {0n; n is a perfect square} is not regular. Q3. Design a Moore machine which counts the occurrence of substring aab in the input string over the alphabet Σ = {a,b}. The transition table for Moore machine is as follows: Present State q0 q1 q2 q3 Next state on a q1 q2 q2 q1 Output b q0 q0 q3 q0 0 0 0 1 Q4. Differentiate among Regular Expression, Regular Language and Regular Grammar. Regular Expression: The regular expressions are useful for representing certain sets of strings in an algebraic fashion. Actually these describe the languages accepted by finite state automata. We give a formal recursive definition of regular expressions over Σ as follows: 1. Any terminal symbol (i.e. an element of Σ), ε and Φ are regular expressions. When we view a in Σ as a regular expression, we denote it by a. 2. The union of two regular expressions R1 and R2 written as R1 + R2, is also a regular expression. 3. The concatenation of two regular expressions R1 and R2, written as R1R2, is also a regular expression. 4. The iteration (or closure) of a regular expression R written as R*, is also a regular expression. 5. If R is a regular expression, then (R) is also a regular expression. 6. The regular expressions over Σ are precisely those obtained recursively by the application of the rules 1-5 once or several times. Regular Grammar and Language: A production of the form Aa or A aB, where A, B Є N and a Є Σ, is called a type 3 production. A grammar is called a type 3 or regular grammar if all its productions are type 3 productions. A production S ε is allowed in type 3 grammar but in this case S does not appear on the right-hand side of any production. A language generated by a regular grammar is called a type 3 language or a regular language. Q5. Give a regular expression for language L= {anbm : n ≥ 4,m ≤ 3} Regular expression for language L= {anbm : n ≥ 4,m ≤ 3 } is aaaaa*( Λ + b + bb + bbb) Section-B Q1. Using Arden’s Theorem, find the regular expression for the finite automata, M = (Q , Σ, δ, q0, F) where Q={A,B,C}, Σ={a,b}, q0 = A, F = {B, C} and δ is defined as State Input = a Input = b A A B B B C C C A Write Arden’s Equations after checking for availability of ε moves: Since there is no ε move, we can directly write down the equations as follows: A=Aa+Cb+ε …………..(1) B=Ab+Ba …………..(2) C= Bb+Ca ……………(3) Applying Arden’s on equation 2 & 3, we get B= Aba* ………….(4) and, C= Bba* ………..(5) Now using eq. 4 & 5, C= Aba*ba* ………..(6) Now using eq. 1 & 6, A= Aa+ Aba*ba*b+ε ….(7) Apply Arden’s Theorem on eq. 7, A= (a+ba*ba*b)* ………(8) Using eq. 8, B= (a+ba*ba*b)* ba* And, C= (a+ba*ba*b)* ba*ba* So, Regular Expression can be obtained by adding the values of B & C, = (a+ba*ba*b)* ba* + (a+ba*ba*b)* ba*ba* Section-C Q.1Construct Deterministic finite automata expression: 10 + (0 + 11)0*1 equivalent to following regular