QUESTION BANK SOLUTION Unit 1 Introduction To Finite Automata

3y ago
203 Views
22 Downloads
1.70 MB
56 Pages
Last View : 10d ago
Last Download : 3m ago
Upload by : Ronnie Bonney
Transcription

FLAT10CS56QUESTION BANK SOLUTIONUnit 1Introduction to Finite Automata1. Obtain DFAs to accept strings of a’s and b’s having exactly one a.(5m )(Jun-Jul 10)2.Obtain a DFA to accept strings of a’s and b’s having even number of a’s and b’s.( 5m)(Jun-Jul 10)L ve Applications of Finite Automata. (5m )(Jun-Jul 10)String ProcessingConsider finding all occurrences of a short string (pattern string) within a long string (text string).This can be done by processing the text through a DFA: the DFA for all strings that end with the patternstring. Each time the accept state is reached, the current position in the text is output.Finite-State MachinesA finite-state machine is an FA together with actions on the arcs.StatechartsStatecharts model tasks as a set of states and actions. They extend FA diagrams.Lexical AnalysisDept of CSE, SJBIT1

FLAT10CS56In compiling a program, the first step is lexical analysis. This isolates keywords, identifiers etc., whileeliminating irrelevant symbols. A token is a category, for example “identi fier”, “relation operator” orspecific keyword.4.Define DFA, NFA & Language? (5m)( Jun-Jul 10)Deterministic finite automaton (DFA)—also known as deterministic finite state machine—is a finitestate machine that accepts/rejects finite strings of symbols and only produces a unique computation (orrun) of the automaton for each input string. 'Deterministic' refers to the uniqueness of the computation.Nondeterministic finite automaton (NFA) or nondeterministic finite state machine is a finite statemachine where from each state and a given input symbol the automaton may jump into several possiblenext states. This distinguishes it from the deterministic finite automaton (DFA), where the next possiblestate is uniquely determined. Although the DFA and NFA have distinct definitions, a NFA can betranslated to equivalent DFA using the subset construction algorithmA language is any subset ofLanguages:5. Obtain a DFA to accept strings of a’s and b’s starting with the string ab. (6m )(Dec-Jan 10) (JunJul 12)Dept of CSE, SJBIT2

FLAT10CS56L {ab,aba,abb,abab,abaa,abbb,abba ------}6. Draw a DFA to accept string of 0’s and 1’s ending with the string 011. (4m)( Dec-Jan 10) (JunJul 12)L {011, 0011, 1011, 00011, 01011, 10011, 11011, .},7. Write DFA to accept strings of 0’s, 1’s & 2’s beginning with a 0 followed by odd number of 1’sand ending with a 2. (10m )(Dec-Jan 10) (Jun-Jul 12)Dept of CSE, SJBIT3

FLAT10CS568.Design a DFA to accept string of 0’s & 1’s when interpreted as binary numbers would bemultiple of 3. (5m )(Jun-Jul 11)(Jun-Jul12)9.Find closure of each state and give the set of all strings of length 3 or less accepted byautomaton.(5m )(Jun-Jul 11) (Jun-Jul12)10.Obtain a DFA to accept strings of a’s and b’s having a sub string aa. (5m)(Jun-Jul-11)Dept of CSE, SJBIT4

FLAT10CS5611.Write Regular expression for the following L { an bm : m, n are even} L { an,bm :m 2, n 2}.(5m)(Jun-Jul 11)ab numberOf(a) 1 and numberOf(b) 1 1/2abb numberOf(a) 1 and numberOf(b) 2 1/2abbb numberOf(a) 1 and numberOf(b) 3 1/2aabb numberOf(a) 2 and numberOf(b) 2 2/2 1aaabb numberOf(a) 3 and numberOf(b) 2 3/2 1.5aaaabb numberOf(a) 4 and numberOf(b) 2 4/2 212.δN pq*r01{p,r}{q}{r,s}{p}{p,s}{r}{q,r}I*sConvert above automaton to a DFA.(10m)(Dec-Jan 11)Dept of CSE, SJBIT5

FLAT13.10CS56Convert following NFA to DFA using subset construction method.(10m)(Dec-Jan 11)δ pq*r14.ab{r}{q}I{p}{p,r}{p,q}{r}I{p}Convert the following DFA to Regular Expression (10m)(Dec –Jan-12)Dept of CSE, SJBIT6

FLAT15.10CS56Define NFA. With example explain the extended transition function(5m)(Dec –Jan-12)As with a DFA, we can de ne the extended transition function of an NFA. If the transition function is ,we usually denote the extended transition function by . The basis is that (q; a) : fqg:For the induction step, let S be (q; x). Then (p; xa) : [p2S (p; a):The Subset ConstructionIn order to show that DFAs and NFAs have the same computational power, gave the subset construction,which, given an NFA, constructs a DFA that accepts the same language.The alphabet of the new DFA isthe same as that of the NFA. If Q is the set of states of the given NFA, then the set Q0 of states of the newDFA is P(Q), the power set of Q, that is, the set of all subsets of Q. In another words, a state of the newDFA is a set of states of the NFA.If q0 is the start state of the NFA, then fq0g is the start state of the newDFA. A state in the new DFA is accepting if it contains an accepting state of the NFA. If is thetransition function of the NFA, then we de ne the transition function 0 of the new DFA as follows.Where S is a subset of Q and a is a symbol: 0 (S; a) : [ p2S (p; a):16.Explain the ground rules of finite automata.(5m)(Dec-Jan12)Dept of CSE, SJBIT7

FLATDept of CSE, SJBIT10CS568

FLAT10CS56UNIT 2Finite Automata, Regular Expressions1.P.T. Let R be a regular expression. Then there exists a finite automaton M (Q, , G, q0,A) which accepts L(R). (10m)( June- july 2010)2.Define derivation , types of derivation , Derivation tree & ambiguous grammar. Giveexample for each. (4m)(June- July 2010)Derivation TreeDerivation trees (also called "parse trees" in Sethi's book) are a way to represent the generation of stringsin a grammar. They also give information about the structure of the strings, i.e. the way they are organizedin syntactical categories.DefinitionGiven a grammar G T , N , s , P , a derivation tree t for G is a tree such that:the root is labeled by sthe leaves are labeled by terminal symbolseach intermediate node is labeled by a non-terminal symbol, and, if its label is A, then its children arelabeled by symbols s1 , s2 , . , sn such that there exists a production A :: s1 s2 . sn in PThe labels of the leaves (fringe) represent the string generated by t. We will indicate it by string(t).It is easy to see that a derivation tree represents a set of derivations (usually more than one) for the samestring, and that for each derivation there is a derivation tree for the same string. Hence L(G) coincideswith the set of strings generated by all possible derivation trees for G. More formally, if we denote byDT(G) the set of all derivation trees for G, we have the following result:PropositionDept of CSE, SJBIT9

FLAT10CS56L(G) { alpha in T* alpha string(t) for some t in DT(G) }ExampleLet us consider again the language of numerical expressions, with productionsExp :: Num Exp Exp Exp * ExpWe have that a possible derivation tree for the string 2 3 * 5 is the followingExp/ \/ \/ \Exp Exp / \ / \ / \Num Exp * Exp 2 Num 3Num 5This tree corresponds to several derivations for the same string, which differ only for the choice of thenon-terminal to expand at each derivation step.AmbiguityThe structure of an expression is usually essential to interpret its meaning. The expression 2 3 * 5 forexample has two different values depending on its intended structure: If we assume it to be 2 ( 3 * 5 )(i.e. 3 and 5 grouped together by *) then the result is 17. If, on the other hand, we assume it to be ( 2 3 )* 5, then the result is 25. In order to avoid this kind of ambiguity, it is essential that the grammar generatesDept of CSE, SJBIT10

FLAT10CS56only one possible structure for each string in the language. Since the structure is represented by thederivation tree, we have the following definition:DefinitionA grammar G is ambiguous if there exist a string in L(G) which can be derived by two (or more) differentderivation trees.ExampleThe grammar in the example above is ambiguous, in fact the string 2 3 * 5 can be generated also by thefollowing tree:Exp/ \/ \/ \Exp * Num/ \ / \5/ \Exp Exp Num 2Num 3This tree corresponds to the grouping ( 2 3 ) * 5, while the tree in the example above corresponds to 2 ( 3 * 5 ).There are languages which are intrinsically ambiguous, i.e. it is not possible to eliminate their ambiguitieswithout changing the language.DefinitionDept of CSE, SJBIT11

FLAT10CS56A language L is intrinsically ambiguous if can be generated only by ambiguous grammars, i.e. for everygrammar G such that L L(G), we have that G is ambiguous.Luckily, languages which are interesting from the point of view of programming usually are notintrinsically ambiguous, and therefore we can find non-ambiguous grammars which generates them. Whena (non-intrinsically ambiguous) language L is presented by an ambiguous grammar G, "to eliminate theambiguities of G" means to find another grammar G', which is non ambiguous, and which generates thesame language L.3.Obtain an NFA to accept the followingnabab or aban where n t 0} (6m)(June- July- 2010)languageL {w 17. Convert the following NFA into an equivalent DFA. (10m)( Dec- Jan 2010) (Jun-Jul 12)18. Convert the following NFA to its equivalent DFA(10m)( Dec- Jan 2010) (Jun-Jul 12)Dept of CSE, SJBIT12w

FLAT10CS564.Obtain an NFA which accepts strings of a’s and b’s starting with the string ab. ). (7m)(June- july 2011)5.Define grammar? Explain Chomsky Hierarchy? Give an example (6m)(June- July 2011)A formal grammar of this type consists of:a finite set of production rules (left-hand side right-hand side) where each side consists of a sequence ofthese symbolsa finite set of nonterminal symbols (indicating that some production rule can yet be applied)a finite set of terminal symbols (indicating that no production rule can be applied)a start symbol (a distinguished nonterminal symbol)Dept of CSE, SJBIT13

FLATFor example, the grammar with terminals10CS56, nonterminals, production rulesε (where ε is the empty string)The Chomsky hierarchy consists of the following levels:Type-0 grammars (unrestricted grammars) include all formal grammars. They generate exactly alllanguages that can be recognized by a Turing machine. These languages are also known as the recursivelyenumerable languages. Note that this is different from the recursive languages which can be decided by analways-halting Turing machine.Type-1 grammars (context-sensitive grammars) generate the context-sensitive languages. These grammarshave rules of the form with a nonterminal and , and strings of terminals and nonterminals. The stringsand may be empty, but must be nonempty. The rule is allowed if does not appear on the right side of anyrule. The languages described by these grammars are exactly all languages that can be recognized by alinear bounded automaton (a nondeterministic Turing machine whose tape is bounded by a constant timesthe length of the input.)Type-2 grammars (context-free grammars) generate the context-free languages. These are defined by rulesof the form with a nonterminal and a string of terminals and nonterminals. These languages are exactlyall languages that can be recognized by a non-deterministic pushdown automaton. Context-free languages– or rather the subset of deterministic context-free language – are the theoretical basis for the phrasestructure of most programming languages, though their syntax also includes context-sensitive nameresolution due to declarations and scope. Often a subset of grammars are used to make parsing easier, suchas by an LL parser.Type-3 grammars (regular grammars) generate the regular languages. Such a grammar restricts its rules toa single nonterminal on the left-hand side and a right-hand side consisting of a single terminal, possiblyfollowed by a single nonterminal (right regular). Alternatively, the right-hand side of the grammar canconsist of a single terminal, possibly preceded by a single nonterminal (left regular); these generate thesame languages – however, if left-regular rules and right-regular rules are combined, the language need nolonger be regular. The rule is also allowed here if does not appear on the right side of any rule. Theselanguages are exactly all languages that can be decided by a finite state automaton. Additionally, thisfamily of formal languages can be obtained by regular expressions. Regular languages are commonly usedto define search patterns and the lexical structure of programming languages.6.Is the following grammar ambiguous (7m)(June- July 2011)S - aB bAA - aS bAA aDept of CSE, SJBIT14

FLAT10CS56B - bS aBB bIt is ambiguous because there are two di erent leftmost derivations forthe string aaa:7.Obtain grammar to generate string consisting of any number of a’s and b’s with at leastone b. ( 5m)(Dec- Jan 2011) (Jun-Jul12)8.Obtain a grammar to generate the following language L {WWR Where W {a, b}*}. (5m)(Dec- Jan 2011) (Jun-Jul12)Dept of CSE, SJBIT15

FLAT10CS569.Obtain a grammar to generate the following language: L { 0m 1m2n m 1 and n 0}.(5m)( Dec- Jan 2011)10.Obtain a grammar to generate the following language: ( 5m)(Dec- Jan 2011)L { w n a(w) n b(w) }L { an bm ck n 2m k for n 0, m 0}Dept of CSE, SJBIT16

FLAT10CS5611.Define PDA. Obtain PDA to accept the language L {an bn n 1} by a final state. (5m)(Dec- Jan 2011) (Jun-Jul12)12.Write a short note on application of context free grammar. ( 7m)(Dec- Jan 2012)Well-formed parenthesesThe canonical example of a context free grammar is parenthesis matching, which is representative of thegeneral case. There are two terminal symbols "(" and ")" and one nonterminal symbol S. The productionrules areS SSS (S)S ()The first rule allows Ss to multiply; the second rule allows Ss to become enclosed by matchingparentheses; and the third rule terminates the recursion.Well-formed nested parentheses and square bracketsA second canonical example is two different kinds of matching nested parentheses, described by theproductions:S SSS ()S (S)S []S [S]with terminal symbols [ ] ( ) and nonterminal S.The following sequence can be derived in that grammar:([ [ [ ()() [ ][ ] ] ]([ ]) ])A regular grammarEvery regular grammar is context-free, but not all context-free grammars are regular. The followingcontext-free grammar, however, is also regular.S aS aSDept of CSE, SJBIT17

FLAT10CS56S bSThe terminals here are a and b, while the only non-terminal is S. The language described is all nonemptystrings of s and s that end in .This grammar is regular: no rule has more than one nonterminal in its right-hand side, and each of thesenonterminals is at the same end of the right-hand side.Every regular grammar corresponds directly to a nondeterministic finite automaton, so we know that this isa regular language.Using pipe symbols, the grammar above can be described more tersely as follows:S a aS bSMatching pairsIn a context-free grammar, we can pair up characters the way we do with brackets. The simplest example:S aSbS abThis grammar generates the language , which is not regular (according to the Pumping Lemma for regularlanguages).The special character ε stands for the empty string. By changing the above grammar toS aSb εwe obtain a grammar generating the language instead. This differs only in that it contains the empty stringwhile the original grammar did not.Algebraic expressionsHere is a context-free grammar for syntactically correct infix algebraic expressions in the variables x, yand z:S xS yS zS S SS S-SS S*SS S/SS (S)This grammar can, for example, generate the string(x y)*x-z*y/(x x)as follows:S (the start symbol) S - S (by rule 5) S * S - S (by rule 6, applied to the leftmost S) S * S - S / S (by rule 7, applied to the rightmost S) ( S ) * S - S / S (by rule 8, applied to the leftmost S) ( S ) * S - S / ( S ) (by rule 8, applied to the rightmost S) ( S S ) * S - S / ( S ) (etc.) (S S)*S-S*S/(S) (S S)*S-S*S/(S S) (x S)*S-S*S/(S S) (x y)*S-S*S/(S S) (x y)*x-S*y/(S S) (x y)*x-S*y/(x S) (x y)*x-z*y/(x S) (x y)*x-z*y/(x x)Note that many choices were made underway as to which rewrite was going to be performed next. Thesechoices look quite arbitrary. As a matter of fact, they are, in the sense that the string finally generated isalways the same. For example, the second and third rewrites S * S - S (by rule 6, applied to the leftmost S) S * S - S / S (by rule 7, applied to the rightmost S)Dept of CSE, SJBIT18

FLAT10CS56could be done in the opposite order: S - S / S (by rule 7, applied to the rightmost S) S * S - S / S (by rule 6, applied to the leftmost S)13.Explain finite automata with epsilon transition. (7m)(Dec-Jan 12)An informal treatment of -NFA's, using transition diagrams with f allowed as a label. In the examples tofollow, think of the automaton as accepting those sequences of labels along paths from the start state to anaccepting state. However, each e along a path is "invisible" j i.e., it contributes nothing to the string alongthe path.In Fig. is an -NFAthat a.ccepts decimal numbers con- sisting of:2. A string of digits,1. An optional or - sign,3. A decimal point, and4. Another string of digits. Either this string of digits, or the string (2) canbe empty, but at least one of the two strings of digits must be nonempty.14.Explain the application of regular expression (6m)(Dec-Jan 12) (Jun-Jul12) Search commands such as the UNIX grep or equivalent commands for finding strings that one sees inWeb browsers or text-formatting systems. These systems use a regular-expression-like notation fordescribing pat-terns that the user wants to find in a file. Different search systems convert the regularexpression into either a DFA or an NFA, and simulate that automaton on the file being searched. Lexical-analyzer generators, such as Lex or Flex. Recall that a lexical analyzer is the component of acompiler that breaks the source program into logical units (called tokens) of one or more characters thathave a shared significance. Examples of tokens include keywords (e.g., while),identifiers (e.g., any letterfollowed by zero or more letters and/or digits),and Sig,TIS,such as or . A lexical-analyzer generatoraccepts descriptions of the forms of tokens, which are essentially regular expressions, andproduces a DFAthat recognizes which token appears next on the input.Dept of CSE, SJBIT19

FLAT10CS56Unit 3Regular Languages, Properties of Regular Languages1.Prove pumping lemma? (4m)( June-July 2010)For every regular language there is a finite state automaton (FSA) that accepts the language. The numberof states in such an FSA are counted and that count is used as the pumping length p. For a string of lengthat least p, let s0 be the start state and let s1, ., sp be the sequence of the next p states visited as the string isemitted. Because the FSA has only p states, within this sequence of p 1 visited states there must be atleast one state that is repeated. Write S for such a state. The transitions that take the machine from the firstencounter of state S to the second encounter of state S match some string. This string is called y in thelemma, and since the machine will match a string without the y portion, or the string y can be repeated anynumber of times, the conditions of the lemma are satisfied.For example, the following image shows an FSA.The FSA accepts the string: abcd. Since this string has a length which is at least as large as the number ofstates, which is four, the pigeonhole principle indicates that there must be at least one repeated stateamong the start state and the next four visited states. In this example, only q1 is a repeated state. Since thesubstringbc takes the machine through transitions that start at state q1 and end at state q1, that portioncould be repeated and the FSA would still accept, giving the stringabcbcd. Alternatively, the bc portioncould be removed and the FSA would still accept giving the string ad. In terms of the pumping lemma, thestring abcd is broken into an x portion a, a y portion bc and a z portion d.2.Prove that L {w w is a palindrome on {a,b}*} is not regular. i.e., L {aabaa, aba,abbbba, } ( 8m)(June-July 2010)The case n 0 just means that u ε (so ε always matches r ); and the case n 1 just m

FLAT 10CS56 Dept of CSE, SJBIT 1 QUESTION BANK SOLUTION Unit 1 Introduction to Finite Automata 1. Obtain DFAs to accept strings of a’s and b’s having exactly one a.(5m )( Jun-Jul 10) 2. Obtain a DFA to accept strings of a’s and b’s having even number of a’s and b’s.( 5m)( Jun-Jul 10)

Related Documents:

Northern Bank & Trust Co. Patriot Community Bank People's United Bank Pilgrim Bank Radius Bank RTN Federal Credit Union Santander StonehamBank TD Bank The Cooperative Bank The Savings Bank The Village Bank Walpole Cooperative Bank Wellesley Bank Winchester Co-operative Bank Abington Bank Bank of Canton Blue Hills Bank Boston Private Bank & Trust

M/s G.M. Kapadia & Co., Chartered Accountants Bankers HDFC Bank Ltd. (Primary Banker) Axis Bank Ltd. Bank of Baroda Bandhan Bank Ltd. Citibank N.A. CSB Bank Ltd. DCB Bank Ltd. Deutsche Bank ESAF Small Finance Bank ICICI Bank Ltd. IDFC Bank Ltd. Indian Bank RBL Bank Ltd. Saraswat Co-op Bank Ltd. State Bank of India Suryoday Small Finance Bank Ltd.

Solution to 79 Question 80 Solution to 80 Question 81 Solution to 81 Question 82 Solution to 82 Question 83 Solution to 83 Question 85 Solution to 85 Question 86 Solution to 86 Chapter 7: Cables Question 88 Solution to 88

10. HDFC Bank Limited 11. ICICI Bank Ltd 12. Indian Overseas Bank 13. ING Vysya Bank 14. Kotak Bank -Virtual card 15. Shivalik Bank 16. Standard Chartered Bank 17. State Bank of Bikaner and Jaipur 18. State Bank of India 19. State Bank of Mysore 20. State Bank of Travencore 21. Syndicate Bank 22. The Federal Bank Ltd 23. The Karur Vysya Bank Ltd

commerce bank eastern bank-east west bank everbank firstbank first hawaiian bank-first horizon bank firstmerit bank-first national of. nebraska first niagara flagstar bank f.n.b.corp. frost national bank fulton financial hancock bank iberiabank m b financial new york community banks old national, bank one west bank people's united bank raymond .

State Bank of India State Bank of Mysore State Bank of Patiala State Bank of Travancore Syndicate Bank Tamilnadu Mercantile Bank TNSC Bank UCO Bank Union Bank of India United Bank of India Vijaya Bank YES Bank . Instruction to follow during first time use of Karur Vysya

Access Bank Acleda Bank Agricultural Bank of China ANZ Arab International Bank Banco Sabadell Bank ABC Bank Alfalah Bank Islam Brunei Darussalam Bank of America Bank of Baroda Bank of China BankUnited Banorte Barclays BBVA Belsize BMCE Bank BMO Capital Markets BNL - BNP Paribas BNP Paribas BNY Mellon Bpifranc

Bank of Baroda. 31: Bank of Beirut (UK) Limited . 32: Bank of China. 33: Bank of Communications (UK) Limited. 34: Bank of Cyprus UK Limited. 35: Bank of East Asia Limited. 36: Bank of India. 37: Bank of Montreal . 38: Bank of New York Mellon (UK Group) 39: Bank of Nova Scotia, The . 40: Bank of Taiwan - Lon