Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
SIDDAGANGA INSTITUTE OF TECHNOLOGY, TUMKUR Department of Computer Science and Engineering. Tutorials-2015 Even Semester Sub:Finite Automata and Formal Languages Tutorial-1 1. Define the transition function for DFA,NFA and ε-NFA mathematically. 2. If L= {a, ab} then L2= ________________. 3. Minimum number of states needed for a DFA that accepts all strings of x’s and y’s whose length is divisible by 1000 is ________. 4. Draw a DFA to accept all strings of a’s & b’s with atmost 2 consecutive b’s. Derive the output of extended transition function for the string aabbaa from the beginning state. 5. Draw a DFA to accept strings of 0’s & 1’s beginning with 01 and ending with 11. 6. Obtain NFA for the Language: (00* + 10*) 11. 7. Convert the NFA obtained in the previous question to DFA using Lazy Evaluation method. Tutorial-2 1. What is the start state of DFA after converting the following ε-NFA to an equivalent DFA? E = ( Q , Σ , δ , q0 , F), Q ={ q0,q1,q2} ,Σ = { a, b, c},q0 = q0 , F = {q2} & δ is as follows: δ(q0,a) = q0, δ(q0,b) = Φ, δ(q0,c) = Φ ,δ(q0, ε) = q1,δ(q1,a) = Φ, δ(q1,b) = q1, δ(q1,c) = Φ ,δ(q1, ε) = q2, δ(q2,a) = Φ, δ(q2,b) = Φ, δ(q2,c) = q2,δ(q2, ε) = Φ 2. Let M = {Q, Σ, δ, q0, F} be an FA. A string w Σ* is accepted by M if δ*(q0, w) Q δ*(q0, w) F δ*(q0, w) F None of the above 3. Obtain a DFA to accept strings of a’s and b’s such that L={w|w Є (a+b)* such that (number of a’s of w) mod 3 = 0 and (number of b’s of w) mod 2 = 0}. 4. Design a DFA to accept: Even numbers in binary Decimal numbers divisible by 3(2m) Tutorial-3 1. Differentiate the following: i. L + and L* ii. Alphabet and String iii. Transition function of DFA,NFA and ε-NFA iv. Extended Transition function of DFA,NFA and ε-NFA v. Ø and ε vi.Σ + and Σ * 2. Converting the following ε-NFA to an equivalent DFA. E = ( Q , Σ , δ , q0 , F), Q ={ q0,q1,q2} ,Σ = { a, b, c},q0 = q0 , F = {q2} & δ is as follows: δ(q0,a) = q0, δ(q0,b) = Φ, δ(q0,c) = Φ ,δ(q0, ε) = q1,δ(q1,a) = Φ, δ(q1,b) = q1, δ(q1,c) = Φ ,δ(q1, ε) = q2, δ(q2,a) = Φ, δ(q2,b) = Φ, δ(q2,c) = q2,δ(q2, ε) = Φ 3. Give DFA’s to accept the following languages over the alphabet{ 0,1}: i) The set of string of 0’s and1’s except those containing the substring 001. ii) L = {W such that | W | mod 3 > | W | mod 2 where W ∑* and ∑ = {0, 1}} Tutorial-4 Obtain RE for the following Regular Languages 1) To accept strings of a’s and b’s of length <2 2) To accept strings of a’s and b’s of length <=2 3) To accept strings of a’s and b’s of length <=10 4) To accept strings of a’s and b’s having even length 5) To accept strings of a’s and b’s having odd length 6) To accept language consisting of strings of a’s and b’s with alternate a’s and b’s Tutorial-5 Obtain RE for the following Regular Languages 1)To accept language consisting of strings of 0’s and 1’s with at most one pair of consecutive 0’s 2) To accept language containing at least 1a and at least 1b where ∑= {a,b,c} 3) L(R) = {w | w ∊ {0, 1}* with at least 3 consecutive 0’s 4) To accept strings of a’s and b’s ending with ‘b’ and has no substring aa 5) To accept strings of 0’s and 1’s having no 2 consecutive 0’s 6) To accept strings of a’s and b’s starting with ‘a’ and ending with ‘b’ 7) To accept strings of a’s and b’s whose second symbol from the right end is ‘a’ 8) For strings of a’s and b’s whose 10th symbol from the right end is ‘a’ 9) To accept strings of a’s and b’s such that 3rd symbol from the right is ‘a’ and 4th symbol from the right is ‘b’ Tutorial-6 1.Consider the following DFA D: D = ( Q , Σ , δ , q0 , F) where, Q ={ q1, q2 ,q3} ,Σ = { 0,1},q0 = q1 , F = { q3}, δ is as follows : δ (q1, 0) = q2, δ (q1, 1) = q1, δ (q2, 0) = q3, δ (q2, 1) = q1, δ (q3, 0) = q3, δ (q3, 1) = q2. Find the regular expression R13(3) and minimize the expression as much as possible. 2.State and prove pumping lemma for regular languages. Show that L = {ww R | w Є (0+1)*} is not regular. 3.Prove that regular languages are closed under reversal operation i.e. if L is regular language, so is L R. 4.Suppose L is the language defined for a regular expression R i.e. L = L (R). Show that we can construct an equivalent -NFA E with exactly one accepting state and also L = L (E). Clearly specify basis and induction steps. Apply the steps to convert the regular expression (0+1)* 1 (0+1) to an -NFA. Tutorial-7 1.Write the regular expression for the following finite automata by eliminating states. 0 *p s q p r r s q 1 p s q r 2.State the pumping lemma of a regular language. Prove that the language L= { O n : n is Prime} is not regular. 3.Prove that if L1 and L2 are two regular languages then so is L1 - L2 Tutorial-8 1.Obtain a Regular expression for the following assuming ∑= { 0,1} a. L = { anbmcp / n<=4, m>=2, p<=2} b. L = { a2nb2m+1 / n>=0,m>=0} c. L = { w / |w| mod 3 =0} 2.Show that the regular languages are closed under concatenation and difference operations. 3.Briefly describe the different applications of regular languages. 4.Show that the regular languages are closed under reversal and homomorphism operations. Tutorial-9 1. Define Alphabet with an example. 2. If L= {a,b} then L3= ________________. 3. Number of states needed for a DFA that accepts all binary numbers divisible by either 10 or 15 is ________. 4. Consider the transition table given in Table-1 for ε -NFA with seven states: i. Find δ*(1, aabb). ii. Find λ-closure 1,2 and 4. 6. Design a DFA to accept ODD strings in binary. Decimal numbers divisible by 4 7. Differentiate the following: i.Ø and ε ii.Σ + and Σ * iii.Transition function of DFA and ε -NFA 8. What is the ECLOSE (q1) in the following ε-NFA? E = ( Q , Σ , δ , q0 , F), Q ={ q0,q1,q2} ,Σ = { a, b, c},q0 = q0 , F = {q2} & δ is as follows: δ(q0,a) = q0, δ(q0,b) = Φ, δ(q0,c) = Φ ,δ(q0, ε) = q1,δ(q1,a) = Φ, δ(q1,b) = q1, δ(q1,c) = Φ ,δ(q1, ε) = q2, δ(q2,a) = Φ, δ(q2,b) = Φ, δ(q2,c) = q2,δ(q2, ε) = {q0,q1} states 1 2 3 4 5 6 7 a Ø {3} Ø {4} Ø {5} Ø B Ø Ø {4} Ø {6,7} Ø Ø Table-1 Tutorial-10 ε {2} {5} Ø {1} Ø Ø {1} Answer the questions from 1-6 by considering the following grammar: S AB A 0A1 01 B 2B 1. 2. 3. 4. 5. 6. Variables present in the grammar ____________________. Terminals present in the grammar ________________________. Language accepted by the grammar is: a. L={ 0m 1m 2n | m >=1 and n>=0} b. L={ 0n 1m 2n | m >=1 and n>=0} c. L={ 0m 1n 2n | m >=1 and n>=0} d. None Show whether the grammar is ambiguous or not? Write the parse tree which yields 00011122. Show the leftmost derivation of the sentential form 012B. 7. Construct CFG for the language (a+b)3(a+b)* and derive the string aaabb using rightmost derivation. Tutorial-11 1. Design a DFA to accept all binary string having 1’s divisible by 2 and 0’s divisible by 4. 2. Convert the following Regular expression to finite automata a. 01+101 b. (01+1)* Simplified form of the Regular expression 0 * + 0*11* is: (Note: Show the Simplification) a. 0*1* b. 0*1+ c. 0+1* d. None of the above 3. 4. If L is defined by the regular expression 1*(1+0), then LR is defined by the expression: _______________________. 5. Consider the following automata. The language of the L1 intersection L2 is: (Show the construction). a. (a+b)*a b. (a+b)*b c. Φ d. None Tutorial-12 1. Convert the automata to Regular Expression by eliminating states. 2. 3. 0 1 →A B A B C B *C C C Convert the following Regular expression to finite automata a. ab+ba* b. (ba)*+a* Let h be the homomorphism defined as h : {a, b} {0, 1}*. h(a)=10 and h(b)=001. h(abb) is:_____________ Tutorial-13 1. Consider the following automata. Let L be the language accepted by the above automaton. The language accepted by L R is: (Show the DFA) 2. a. ba(b+a)* b. ba(a+b)* c. ab(b+a)* d. both a and b\ Convert the following Finite Automata to Regular Expression 2 a b →P P Q Q Q R *R R R Tutorial-14 1. 2. Convert the following Automata to regular Expression. 0 1 →*A B A B A B Consider the following automata. M1: 3. M2 Let L1 and L2 be the languages accepted by the above automata. The language accepted by L1 L2 is: (Show the DFA) a. 11*0(0+1)*+00*1(0+1)* b. 00*1(0+1)*+ 11*0(0+1)* c. Both a and b d. Only a e. Only b f. None Tutorial-15 1. 1 2 3 Match the following I X→K X→ε X→A,B→D,B and D are 4 5 X→A|B,A→a,B→Bb,B is X→aBB II A B C Not reachable Epsilon production Is both in CNF and GNF D E F G H Not generating Is in CNF Is in GNF not generating and not reachable Unit Production 2. Design a PDA to accept the language L={an-2bn|where n, m>=0} 3. Write the 7 tuple notation for the question . 4. Write the ID for aabbbb. 5. Define the language of PDA by final state. Tutorial-16 1. Match the following I II 1 Y→K A Not generating 2 Y→ε B not generating and not reachable 3 Y→A,B→D,B and D are C Unit Production 4 5 Y→A|B,A→a,B→Bb,B is Y→aBB D E F G H Is both in CNF and GNF Not reachable Epsilon production Is in CNF Is in GNF 2.Design a PDA to accept the language L={anbn-2|where n, m>=0} 3. Write the 7 tuple notation for the question 2. 4. Write the ID for aabbbb. 5. Define the language of PDA by empty stack Tutorial-17 Match the following 1 2 3 I S→K Z→ε Z→A,B→D,B and D are A B C Is in CNF Is in GNF Not reachable II 4 Z→A|B,A→a,B→Bb,B is D Epsilon production 5 S→aBB E Not generating F not generating and not reachable G Unit Production H Is both in CNF and GNF 2.Design a PDA to accept the language L={an-3bn|where n, m>=0} 3. Write the 7 tuple notation for the question 2. 4. Write the ID for aabbbb. 5. Define the language of PDA by final state Tutorial-18 Obtain DFA for the following languages: L= {(01) i 12j where i>=1, j>=1} L= {an where n>=0} L={ wbab | w Є { a, b }* } L={ w ( ab + ba ) | w Є { a, b }* } To accept strings divisible by 3 on ∑ = { 0,1, 2…...9 } L = { an bm : (n + m) is even } L = (w : na(w) mod 3 ≠ 0 } L = {x {0, 1 }* | |x| ≥ 3 and the 3rd symbol from the right in x is 1} Strings consisting of even number of 0’s followed by even number of 1’s Language of all strings in { 0, 1}* with Next-to-Last symbol is 0. 1. Tutorial-19 Obtain an NFA to accept strings of a’s and b’s ending with ab or ba. From this obtain an equivalent DFA 2. Convert the following NFA to its equivalent DFA using modified subset construction method 2 a 3 0 1 6 4 b 5 3. Consider the following ε – NFA : -->p q ε a b c {q, r} Φ Φ {p} {q} {r} {r} {q, p} 7 1 a 8 b 9 b 10 1. i) *r Φ Φ Φ Φ Compute the e- closure of each state ii) Give all the strings of length three or less accepted by the automata iii) Convert the automaton to DFA Tutorial-20 Using the subset construction method find an equivalent DFA of the following NFA 0 1 -> p {q,s} {q} *q {r} {q,r} r {s} {p} *s Φ {p} 2. Design NFA to accept the strings { abc, abd, aacd } over the alphabet {a, b, c,d }. Tutorial-21 Give Regular Expressions for the following languages:. a. Language of all strings of 0’s and 1’s such that number of 0’s is odd. b. L = { 02n 12n+1 | n >=0 }. c. Strings not containing 00. d. Language of all strings of 0’s and 1’s such that each string of even length. e. L = (w : na(w) mod 3 ≠ 0 } f. all strings containing exactly one a. g. all strings containing no more than 3 a’s Tutorial-22 Convert the following DFA to a regular expression using state elimination method. 0 1 P *P S S Q P Q R R R S Q 2. Suppose h is the homomorphism from the alphabet { 0,1, 2 } to the alphabet { a, b } defined by : h(0) = a; h(1) = ba, and h(2) = ab. What is h( 01212 )? 1. If L is the language L( 01*2 ), What is h(L)? Suppose L is the language { ababa } that is the language consisting of only one string ababa, What is h-1 (L)? 1. Tutorial-23 What do you mean by ID of a PDA? Design a PDA to accept the language L = { a nbm cn+m | n 0, m 0 } by final state. Also give its graphical representation and sequence of moves made by the PDA for the string “abbcccc”. 2. Convert the following CFG to a PDA S aABC A aB | a B bA | b Ca 1. Tutorial-24 State the conditions to be met for the PDA to be deterministic. 2. Define a PDA. Design a PDA to accept the following language by final state. L = { w : w ε { a, b }* and na(w) nb(w) } Convert the PDA P = ( { p,q }, { 0,1 ) , { Z, X }, δ, q, Z } to a CFG, if δ is given by δ(q, 1, Z) = { (q, XZ) } δ(q, 1, X) = { (q, XX) } δ(q, 0, X) = { (p, X) } δ(q, ε, X) = { (q, ε) } δ(p, 1, X) = { (p, ε) } δ(p, 0, Z) = { (q, Z ) } 3. If L1 and L2 are two CFL’s then Prove that L1 U L2, L1.L2 are CFL’s. Tutorial-25 1. Give the formal definition of Turing Machine. Design a Turing Machine to accept the language L = { anbncn | n >= 1 } Give the graphical representation for it and also show the moves made by the Turing machine for the string aabbcc 2. Convert the following grammar into CNF. S AACD A aAb | C aC | a D aDa | bDb |c Tutorial-26 1. What are ambiguous grammars? Give the equivalent unambiguous grammar for the following EE-E EE+E EE/E EE*E E(E)|I I a|b 2. List the conditions to construct parse trees. Construct parse tree for the string 01010101010 On grammar S->0S0 | 1S1 |1| 0| ε 3. Construct grammars for i) L = { w | n(a) ≠ n(b)} ii) L = { an b3n ;n ≥ 0}