Formal Language & Automata Theory
Formal Language & Automata Theory
Formal Language & Automata Theory
2 Marks Question and Answer Subject Code & Name: Formal Language and Automata Theory Prepared by: M. Kavitha Lecturer/CSE R.Durga Lecturer/CSE
UNIT-I 1. Define set. A set is a collection of objects. E.g.: The collection of the four letters. S={ a,b,c,d}
2. Define function. A function is a rule that assigns to elements of one set a unique element of another set
3. Define relation. A relation is a set of pairs. The first component of each pair is chosen from a set called the domain and second component of each pair is chosen from a set called the range.
4. Give the examples/applications designed as finite state system . Text editors and lexical analyzers are designed as finite state systems. A lexical analyzer scans the symbols of a program to locate strings corresponding to identifiers, constants etc, and it has to remember limited amount of information.
Page 1
8. Define language. The language can be defined as a collection of strings or words over certain input set.
9. Define Abstract machines with e.g. The computer which performs computation are not actual computers they are abstract machine E.g.: Finite Automata, Push down automata and Turing machine.
FA consists of a finite set of states and a set of transitions from state to state that occur on input symbols chosen from an alphabet . Finite Automaton is denoted by a 5tuples (Q,,,q0,F), where Q is the finite set of states , is a finite input alphabet, q0 in Q is the initial state, F is the set of final states and is the transition mapping function Q * to Q.
11. Define DFA. A DFA consists of A=( Q,,,q0,F) Where Q is the finite set of states , is a finite input alphabet, q0 in Q is the initial state, F is the set of final states and is the transition mapping function Q * to Q.
12. Define NFA A NFA consists of A=( Q,,,q0,F) Where Q is the finite set of states ,
Page 2
13. Define Transition diagram Transition diagram is a directed graph in which the vertices of the graph correspond to the states of FA. If there is a transition from state q to state p on input a, then there is an arc labeled a from q to p in the transition diagram.
14. What are the applications of automata theory? In compiler construction. In switching theory and design of digital circuits. To verify the correctness of a program. Design and analysis of complex software and hardware systems. To design finite state machines such as Moore and mealy machines.
15. What are the components of Finite automaton model? The components of FA model are Input tape, Read control and finite control. (a)The input tape is divided into number of cells. Each cell can hold one i/p symbol. (b)The read head reads one symbol at a time and moves ahead. (c)Finite control acts like a CPU. Depending on the current state and input symbol read from the input tape it changes state.
16. Differentiate NFA and DFA. NFA or Non Deterministic Finite Automaton is the one in which there exists many paths for a specific input from current state to next state. NFA can be used in theory of computation because they are more flexible and easier to use than DFA. Deterministic Finite Automaton is a FA in which there is only one path for a specific input from current state to next state. There is a unique transition on each input symbol
Page 3
19. Define star closure and positive closure. Star closure zero or more. Occurrence Positive closure one or more occurrence (eg) a* = { ,a,aa,.} a+ = {a,aa,.} L+ = L* - {}
20. Define NFA with -transition. Is the NFAs with -transitions are more powerful that NFAs without -transition? The NFA with - moves defined by 5tuple or quintyple as similarly as NFA, except (Q,, ,qo,F) with all components as before and : Qx(U{ }) = 2Q No, NFA with -transition and NFA without -transition have the same power.
the
21. Define Finite State Systems The finite automaton is a mathematical model of a system, with discrete inputs outputs and a finite number of memory configuration called states. and
22. Is it true the language accepted by NFA is different from the regular language? Justify. Your answer. No, it is false. For every regular expression r there exists a NFA with -transition that accepts L(r).
Page 4
1. What is a regular expression? A regular expression is a string that describes the whole set of strings according to certain syntax rules. These expressions are used by many text editors and utilities to search bodies of text for certain patterns etc.
Definition is: Let be an alphabet. The regular expression over and the sets they denote are: i. is a r.e and denotes empty set. ii. is a r.e and denotes the set {} iii. For each a in , a+ is a r.e and denotes the set {a}. iv. If r and s are r.e denoting the languages R and S respectively then (r+s), (rs) and (r*) are r.e that denote the sets RUS, RS and R* respectively
2. List out the operator of regular expression. 1. Union of two Languages 2. Concatenation of two Languages 3.Closure of a Language
3. Write a r.e to denote a language L which accepts all the strings which begin or end with either 00 or 11. The r.e consists of two parts: L1= (00+11) (any no of 0s and 1s) = (00+11) (0+1)* L2= (any no of 0s and 1s)(00+11) = (0+1)*(00+11)
Page 5
5.Construct a r.e for the language over the set ={a,b} in which total number of as are divisible by 3 ( b* a b* a b* a b*)*
(01)*= { , 01 ,0101 ,010101 ,..} All combinations with the pattern 01.
(0+1)+ = {0,1,01,10,1000,0101,.} 7 .Reg exp denoting a language over ={1} having (i) even length of string (ii) odd length of a string
(i) Even length of string R=(11)* (ii) Odd length of the string R=1(11)*
8.Reg exp for: (i)All strings over {0,1} with the substring 0101 (ii)All strings beginning with 11 and ending with ab (iii)Set of all strings over {a,b}with 3 consecutive bs. SNSCT Department of Compute Science and Engineering Page 6
9. Reg exp for the language that accepts all strings in which a appears tripled over the set ={a}
reg exp=(aaa)* 10. What is the closure property of regular sets? The regular sets are closed under union, concatenation and Kleene closure. r1Ur2= r1 +r2 r1.r2= r1r2 ( r )*=r* The class of regular sets are closed under complementation, substitution, homomorphism and inverse homomorphism.
11. Write the exp for the language starting with and has no consecutive bs reg exp=(a+ab)*
12. What is the order of precedence of operators used in regular expression? i. Operator is having the highest precedence. ii. Next the concatenation or dot operator (.). iii. + Operator is having the lowest precedence. iv. 13. Describe the algebra of regular expression. Regular expressions obey many laws of arithmetic. a. Union and Concatenation are associative. b. Union is commutative. c. Union is idempotent. 14. Define pumping lemma for regular languages.
Page 7
The emptiness is defined by checking whether there is a path from the start sate to some accepting state. If there is a path available the languages non-empty. If the accepting states are separated from the start state then the language is empty. 16 Write the formula for convert DFA to RE (Regular expression).
17. List the application of regular expression. a. Regular expression in UNIX b. Lexical Analysis. c. Finding Patterns in a Text 18. What do you mean by equivalence and minimization of DFA? For each DFA it is possible to find an equivalent DFA which contains as few s any DFA accepting the same language. states as
Page 8
1. What are the applications of pumping lemma? Pumping lemma is used to check if a language is regular or not. (i) Assume that the language (L) is regular. (ii) Select a constant n. (iii) Select a string(z) in L, such that |z|>n. (iv) Split the word z into u,v and w such that |uv|<=n and |v|>=1. (v) You achieve a contradiction to pumping lemma that there exists an
2.What are the applications of Regular expressions? Lexical analyzers and Text editors are two applications. Lexical analyzers: The tokens of the programming language can be expressed using regular expressions. The lexical analyzer scans program and separates the tokens. For eg identifier can be expressed as a regular expression as: (letter)(letter+digit)* If anything in the source language matches with this reg exp then it is recognized as an identifier.The letter is{A,B,C,..Z,a,b,c.z} and digit is {0,1,9}.Thus reg exp identifies token in a language. the input
Text editors: These are programs used for processing the text. For example UNIX text editors uses the reg exp for substituting the strings such as: S/bbb*/b/
Page 9
4. What is Ardens Theorem? Ardens theorem helps in checking the equivalence of two regular expressions. Let P and Q be the two regular expressions over the input alphabet . The regular expression R is given as :R=Q+RP Which has a unique solution as R=QP*. 5. Define Homomorphisms. A string homomorphism is a function on string that works by substituting a particular string for each symbol.
6.. Define Inverse Homomorphisms Homomorphisms may also be applied backwards and this mode they also preserve regular language.
7. What are the closure properties of regular languages? i. ii. iii. iv. v. vi. vii. viii. ix. Union Intersection Complement Difference Reversal Closure. Concatenation. Homomorphism. Inverse Homomorphism.
Page 10
UNIT-IV
1. Define a context free grammar A context free grammar (CFG) is denoted as G=(V,T,P,S) where V and T are finite set of variables and terminals respectively. V and T are disjoint. P is a finite set of productions each is of the form A-> where A is a variable and is a string of symbols from (V U T)*.
2. What are the uses of Context free grammars? Construction of compilers. Simplified the definition of programming languages. Describes the arithmetic expressions with arbitrary nesting of balanced parenthesis { (, ) }. Describes block structure in programming languages. Model neural nets. * 3. The language generated by G ( L(G) ) is {w | w is in T* and S =w .That is a G String is in L(G) if: (1) The string consists solely of terminals. (2) The string can be derived from S. 4. What is (a) CFL (b) Sentential Form? L is a context free language (CFL) if it is L(G) for some CFG G. A string of terminals and variables is called a sentential form if: * S => , where S is the start symbol of the grammar. 5. What is the language generated by the grammar G=(V,T,P,S) where P={S->aSb, S->ab}? S=> aSb=>aaSbb=>..=>anbn Thus the language L(G)={ anbn| n>=1}.The language has strings with equal number of as and bs.
Page 11
7. What is an ambiguous grammar? A grammar is said to be ambiguous if it has more than one derivation trees for a sentence or in other words if it has more than one leftmost derivation or more than one rightmost derivation. 8.Give the context free grammar for generating the ;amgiage L={anb2n;n1} SSbb Sabb_
9. Consider G whose productions are SaAS_a, ASbA_SSba. Show that S=>Aas =>aSbAS =>aabAS =>aabbaS =>aabbaa
S=>aabbaa
10. Find the language generated by a CFG. G=({S},{0,1},{S0|1| , S0S0|1S1|S) S =>0S0 =>01S10 =>0I0I0 S =>1S1 =>10S01 =>10001
L= { w;w is a palindrome}
Page 12
12 .Define Pushdown Automata. A pushdown Automata M is a system (Q, , , ,q0, Z0,F) where Q is a finite set of states. is an alphabet called the input alphabet. is an alphabet called stack alphabet. q0 in Q is called initial state. Zo in is start symbol in stack. F is the set of final states. is a mapping from Q X ( U { } ) X to finite subsets of Q X *.
13. Compare NFA and PDA. NFA 1. The language accepted by NFA is the regular language. 2. NFA has no memory. 3. It can store only limited amount of information 4. A language/string is accepted only by reaching the final state. PDA 1.The language accepted by PDA is Context free language. 2. PDA is essentially an NFA with a stack(memory). 3 It stores unbounded limit of information. 4. It accepts a language either by empty
Page 13
14. What are the different types of language acceptances by PDA and define them, Two types 1. Acceptance by final state 2. Acceptance by empty stack
15.Is it true that the language accepted by a PDA by empty stack and final states are different languages. No, because the languages accepted by PDA s by final state are exactly the languages accepted by PDAs by empty stack.
16. What is the additional feature of PDA has when compared with NFA? Is PDA superior over NFA? Is PDA superior over NFA in the sense of language Justify your answer: Additional features of PDA: a) PDA is eventually a FA with a stack. b) PDA can accept context free languages. c) PDA can recognize the context free languages which are not regular. Yes, PDA is superior over NFA in the sense of languages. acceptance?
17. Is it true the nondeterministic PDA is more powerful than that of deterministic justify your answer. Yes, wwR is accepted by NPDA but not any DPDA in the sense of language acceptance.
PDA?
18. Regular Language: A Language can be described by DFA or NFA. Context free language cannot be described by DFA (or) NFA since there is no SNSCT Department of Compute Science and Engineering Page 14
1. d(q,a,b)contains almost one element. 2. If d(q,l,b) is not empty, then d(q,c,b) must be empty for overy c_ , q_Q, b_G most one
The first condition says that for any given input symbol and any stack top, at move can be made.
The second condition say that when a l move is possible for some configuration, no input consuming alternative is available
20. What are the properties of the CFL generated by a CFG? Each variable and each terminal of G appears in the derivation of some word in L There are no productions of the form A->B where A and B are variables.
21. Give examples of languages handled by PDA. (1) L={ anbn | n>=0 },here n is unbounded , hence counting cannot be done by finite memory. So we require a PDA ,a machine that can count without limit. (2) L= { wwR | w {a,b}* } , to handle this language we need unlimited counting capability .
22 Is NPDA (Nondeterministic PDA) and DPDA (Deterministic PDA)equivalent? The languages accepted by NPDA and DPDA are not equivalent.
23. State the equivalence of acceptance by final state and empty stack. If L = L(M2) for some PDA M2 , then L = N(M1) for some PDA M1. If L = N(M1) for some PDA M1 ,then L = L(M2) for some PDA M2.
Page 15
24. State the equivalence of PDA and CFL. If L is a context free language, then there exists a PDA M such that L=N(M). If L is N(M) for some PDA m, then L is a context free language.
25. Define Deterministic PDA. A PDA M =( Q, , , ,q0, Z0 ,F ) is deterministic if: For each q in Q and Z in , whenever (q, ,Z) is nonempty ,then (q,a,Z) is empty for all a in . For no q in Q , Z in , and a in U { } does (q,a,Z) contains more than one element. (Eg): The PDA accepting {wcwR | w in ( 0+1 ) * }.
26. State the equivalence of acceptance by final state and empty stack. If L = L(M2) for some PDA M2 , then L = N(M1) for some PDA M1. If L = N(M1) for some PDA M1 ,then L = L(M2) for some PDA M2. where L(M) = language accepted by PDA by reaching a final state. N(M) = language accepted by PDA by empty stack.
27. What is the informal definition of PDA? A PDA is a computational machine to recognize a Context free language. Computational power of PDA is between Finite automaton and Turing machines. The PDA has a finite control, and the memory is organized as a stack.
28. Give an example of Nondeterministic CFL The language L={ wwR : w {a,b}+ } is a nondeterministic CFL.
Page 16
1. What is a formal language? Language is a set of valid strings from some alphabet. The set may be empty,finite or infinite. L(M) is the language defined by machine M and L( G) is the languagedefined by Context free grammar. The two notations for specifying formal languages are: Grammar or regular expression(Generative approach) Automaton(Recognition approach)
2. What are all the normal forms for CFG? Normal forms for CFG are: i. Chomsky normal form. ii. Greiback normal form. 3. What are the three ways to simplify a context free grammar? By removing the useless symbols from the set of productions. By eliminating the empty productions. By eliminating the unit productions.
3.. What are the properties of the CFL generated by a CFG? Each variable and each terminal of G appears in the derivation of some word in L There are no productions of the form A->B where A and B are variables.
4. (a)CFL are not closed under intersection and complementation True. (b)A regular grammar generates an empty string True.
Page 17
5. What is Backus-Naur Form (BNF)? Computer scientists describes the programming languages by a notation called Backus- Naur Form. This is a context free grammar notation with minor format and some shorthand. changes in
6. What are the closure properties of CFL? CFL are closed under union, concatenation and Kleene closure. CFL are closed under substitution, homomorphism. CFL are not closed under intersection, complementation. Closure properties of CFLs are used to prove that certain languages are not Context free.
7. State the pumping lemma for CFLs. Let L be any CFL. Then there is a constant n, depending only on L, such that if z is in L and |z| >=n, then z=uvwxy such that : (i) |vx| >=1 (ii) |vwx| <=n and (iii) for all i>=0 uviwxiy is in L.
8. What is the main application of pumping lemma in CFLs? The pumping lemma can be used to prove a variety of languages are not context free . Some examples are: L1 ={ ai c i i>=1} is not a CFL. L2= { aibjcidj | i>=1 and J>=1 } is not a CFL
Page 18
10. Define Grieback normal form? A grammar for which every productions is of the form Aa where A is a variable ,a is a terminal and is a string of variables.
11 Definition A language L is said to be deterministic context free language, if and only if there exists a deterministic pushdown automata (dpda) M such that L = L (M)
Page 19