3 rd Year - Computer Science and Engineering,

Size: px
Start display at page:

Download "3 rd Year - Computer Science and Engineering,"

Transcription

1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING 3 rd Year - Computer Science and Engineering, 5th Semester Theory of Computation QUESTION BANK 2 Marks Question and Answer 1. Define set. A set is a collection of objects. UNIT-I E.g.: The collection of the four objects are. 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. 6. Define alphabet. A finite set of non-empty set of symbols is called alphabet. 7. What do you mean by string? A finite sequence of symbols is called string. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 1

2 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. 10. Define Finite Automaton (FA) 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 5- tuples (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, 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 x ( U{ ε}) = 2Q Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 2

3 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? o In compiler construction. o In switching theory and design of digital circuits. To verify the correctness of a program. o Design and analysis of complex software and hardware systems. o 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. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 3

4 17. What is Є-closure of a state q0? Є-closure (q0) denotes a set of all vertices p such that there is a path from q0 to labeled Є. 18. What is a Regular Language? The language accepted by M is L(M) is the set {x δ(q0,x) is in F}. A language is regular if it is accepted by some finite automaton. 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 NFA s with ε-transitions are more powerful that NFA s 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. 21. Define Finite State Systems The finite automaton is a mathematical model of a system, with discrete and inputs outputs and a finite number of memory configuration called states. 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). Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 4

5 23. Design a finite Automata which accepts the only input 101 over the input set Z = {0, 1}. Solution : 24. Find the Ɛ - closure for the following NFA. Ɛ - closure (q0) = {q0,q1,q2} means self-state + Ɛ reachable state. Ɛ - closure (q1) = {q1,q2} Ɛ - closure (q2) = {q2} 25. What is the definition of NFA-ε Machines Definitions for NFA-ε Machines Let M = (Q, Σ, δ,q 0,F) be an NFA-ε and let w be in Σ *. Then w is accepted by M iff δ^({q 0 }, w) contains at least one state in F. Let M = (Q, Σ, δ,q 0,F) be an NFA-ε. Then the language accepted by M is the set: L(M) = {w w is in Σ * and δ^({q 0 },w) contains at least one state in F} Another equivalent definition: L(M) = {w w is in Σ * and w is accepted by M}. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 5

6 FORMAL LANGUAGE AND AUTOMATA THEORY UNIT-II REGULAR LANGUAGES 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 0 s and 1 s) = (00+11) (0+1)* L2= (any no of 0 s and 1 s)(00+11) = (0+1)*(00+11) Hence r.e R=L1+L2 = [(00+11)(0+1)*] + [(0+1)* (00+11)] Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 6

7 4. Construct a r.e for the language which accepts all strings with atleast two c s over the set Σ={c,b} (b+c)* c (b+c)* c (b+c)* 5.Construct a r.e for the language over the set Σ={a,b} in which total number of a s are divisible by 3 ANS : ( b* a b* a b* a b*)* 6. what is: (i) (0+1)* (ii)(01)* (iii)(0+1) (iv)(0+1) (0+1)*= {Є, 0, 1, 01, 10,001,101,101001, } Any combinations of 0 s and 1 s. (01)*= {Є, 01,0101,010101,..} All combinations with the pattern 01. (0+1) = 0 or 1,No other possibilities. (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. Ans :(i) Even length of string R=(11)* (ii) Odd length of the string R=1(11)* 8.write the Regular expression for the following. (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 b s. (iv)set of all strings that end with 1 and has no substring 00 Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 7

8 Ans: (i)(0+1)* 0101(0+1)* (ii)11(1+a+b)* ab (iii)(a+b)* bbb (a+b)* (iv)(1+01)* (10+11)* 1 9. Reg exp for the language that accepts all strings in which a appears tripled over the set Σ ={a}. Ans : 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 complement, substitution, homomorphism and inverse homomorphism. 11. Write the exp for the language starting with and has no consecutive b s.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. 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. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 8

9 14. Define pumping lemma for regular languages. Let L be a regular language. Then there exists a constant n such that for every in L such that w n. w = xyz such that string w a. y Є. b. xy n. c. For all i 0, xyiz Є L. 15. How do you test the emptiness of regular language? 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. List the application of regular expression. a. Regular expression in UNIX b. Lexical Analysis. c. Finding Patterns in a Text 17. 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 any DFA accepting states as the same language. 18. Write the regular expression for the language accepting all combination of a s over the set ={a}. All combination of a s means a may be single, double, triple and so on. There may be the case that a is appearing for zero times, means a null string. That is we accept the set of { Ɛ,a,aa,aaa.}. So we can give regular expression for this as R = a * That is kleen closure of a. 19. Design the regular expression for the language accepting all combination of a s except the null string over the set ={a}. The regular expression has to be built for the language. L ={ a,aa,aaa,.} R= a + This is positive closure indicate the set of strings without the null string. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 9

10 20. Design the regular expression for the language containing all the strings containing any number of a s and b;s. The regular expression will be R= (a+b) * 21. Design the regular expression for the language containing all the strings containing any. number of a s and b;s except the null string The regular expression will be R= (a+b) Write a regular expression to denote a language L over *, where = {a,b} such that the 3 rd character from right end of the string is always a. The regular expression will be R = (a+b) * a (a+b) (a+b) 23. Construct r.e for the language L which accepts all the string with at least two b s over the = {a,b}. The regular expression will be R = (a+b) * b (a+b) * b (a+b) * 24. Write a regular expression to denote a language L over *, where = {a,b,c}.such that every string will have atleast one a followed by one b followed by atleast one c. Now in this problem the condition is slightly changed to atleast. That means the null string is not allowed at all. So we can write The regular expression will be R = a + b + c Write a regular expression to denote a language L over *, where = {a,b,c}.such that every string will be such that any number of a s followed by any number of b s followed by any number of c s. The regular expression will be R = a * b * c Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 10

11 FORMAL LANGUAGE AND AUTOMATA THEORY UNIT-III PROPERTIES OF REGULAR LANGUAGES 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) SeAP a constant n. (iii) SeAP 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/ 3. What are the applications of Finite automata? Gives the substitute a single blank for the first string of two or more blanks in a given line. In UNIX text editors any reg exp is converted to an NFA with ε - transitions, this NFA can be then simulated directly. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 11

12 4. What is Arden s Theorem? Arden s 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. Union ii. Intersection iii. Complement iv. Difference Reversal v. Closure. vi. Concatenation. vii. Homomorphism. viii. Inverse Homomorphism. 8. prove that if L1 and L2 are two languages then L1 U L2 is regular. Proof : if L1 and L2 are regular then they have regular expression L1 = L(R1) and L2= L(R2). Then L1 U L2 = L(L1+L2) thus we get L1 U L2 as regular language. ( Any language given by some regular expression is regular). 9. State Pumping Lemma for Regular Languages. Pumping Lemma relates the size of string accepted with the number of states in a DFA Lemma: (the pumping lemma) Let M be a DFA with Q = n states. If there exists a string x in L(M), such that x there exists a way to write it as x = uvw, where u,v, and w are all in Σ* and: n, then 1 uv n, v 1, such that, the strings uv i w are also in L(M), for all i 0 Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 12

13 10. State that Let M = (Q, Σ, δ, q 0, F) be a DFA. Then L(M) is finite iff x < Q for all x in L(M). Proof: (if) Suppose that x < Q for all x in L(M). Since the number of states Q and the number of input symbols Σ are both fixed, it follows that there are at most a finite number of strings of length less than Q. It follows that L(M) is finite (exercise: give an upper bound on the number of such strings). (only if) By contradiction. Suppose that L(M) is finite, but that x Q for some x in L(M). From the pumping lemma it follows that x=uvw, v 1 and uv i w is in L(M) for all i 0. But then L(M) would be infinite, a contradiction. 10. State that Let M = (Q, Σ, δ, q 0, F) be a DFA. Then L(M) is infinite iff there exists an x in L(M) such that x Proof: Q. (if) Suppose there exists an x in L(M) such that x Q. From the pumping lemma it follows that x=uvw, v 1 and uv i w is in L(M) for all i 0. Therefore L(M) is infinite. (only if) By contradiction. Suppose that L(M) is infinite, but that there is no x in L(M) such that x Q. It follows that each x in L(M) has length less than Q. Since the number of states Q and the number of input symbols Σ are both fixed, it follows that there are at most a finite number of strings of length less than Q. It follows that L(M) is finite. A contradiction. Note that the above also follows directly from the previous theorem. 12. Proving that the complement of a regular language is also regular. Let L=L(A) for some DFA A Where A= (Q, S,d, q 0,F) Then Ľ=L(B) where B=(Q, S,d, q 0,Q-F) Then A and B are same other than the fact that their accepting states are different Then any string w is in L(B) if and only if d * (q 0,w) is in Q-F which occurs only if w is not in L(A). Hence Ľ is regular. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 13

14 13. prove that the Closure under Intersection is regular. If L is regular, then complement of L is also regular. If M is regular, then complement of M is also regular. Also union of two regular languages is proved to be regular Hence intersection of two regular languages is also regular. 14.prove that the Closure under Difference is regular. L-M = set of all strings that are in L and not in M i.e. L-M = L M Since Complement of M is regular as M is regular, Intersection of L and M is also regular Hence the difference of two regular languages is regular 15. What is the Homomorphism to a language. Homomorphism to a language is applied by applying it to each of the strings in the language h(l) = {h(w) w is in L} Let L= 10*1 i.e. L={11,101,1001, } Then h(l) = {єє, єabє, єababє, } or (ab) * 16. prove that If L is regular then h(l) is also regular Let L=L( R) for regular expression R Let E be an expression over S Then let h(e) be an expression obtained by replacing each symbol a of S in E by h(a), Then h(r) defines the language h(l). 17. Define Decision Properties of Regular language. A decision property for a class of languages is an algorithm that takes a formal description of a language (e.g., a DFA) and tells whether or not some property holds. Example: Is language L empty? Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 14

15 18. Define the Equivalent states. Two states p and q are said to be equivalent if for all input strings w, d (p,w) is an accepting state if and only if d (q,w) is an accepting state. If two states are not equivalent then we say they are distinguishable (i.e. if they are not equivalent for at least one w. 19. What is the Equivalence and Minimization of Automata? Testing whether two descriptors for regular languages are equivalent, in the sense that they define the same languages. This gives a method to minimize a DFA. 20. prove that The language: L = {0 k 1 k 2 k k 0} (1) is not regular. Proof: (by contradiction) Suppose that L is regular. Then there exists a DFA M such that: L = L(M) We will show that M accepts some strings not in L, contradicting. Since x = m >> n, it follows from the pumping lemma that: x = uvw 1 uv n 1 v, and uv i w is in L(M), for all i 0 Since 1 uv n and n<<m, it follows that 1 uv m. Also, since x = 0 m 1 m 2 m it follows that uv is a substring of 0 m. In other words v=0 j, for some j 1. Since uv i w is in L(M), for all i 0, it follows that 0 m+cj 1 m 2 m is in L(M), for all c 1. But by (1) and (2), 0 m+cj 1 m 2 m is not in L(M), for any c 1, a contradiction. Note that the above proof is almost identical to the previous proof. 21. Write the example for non-regular language. The set of strings over { (,),a,b,z} in which the parentheses ( and ) occur well nested. The set of strings over { a,b,z} which are palindromes. {a n b n / n 0}. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 15

16 22. Example of non-regular language that satisfies the pumping lemma property. L = { c m a n b n / m 1 and n 0 } U {a m b n / m,n 0 } this is Satisfying pumping lemma properties. 23.Is the following language regular? Justify your answer L={0 2n / n>= 1}. This is a language length of string is always even. n =1, L= 00 n =2, L = and so on. Let L = uvw L = 0 2n I Z I = 4n =u v. v w = even length of string. Thus even after pumping 2n to the string we get the even length. So the language L is regular language. 24. Define 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 memory. 25. prove that the Closure under Difference is regular. L-M = set of all strings that are in L and not in M i.e. L-M = L M Since Complement of M is regular as M is regular, Intersection of L and M is also regular Hence the difference of two regular languages is regular. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 16

17 FORMAL LANGUAGE AND AUTOMATA THEORY UNIT-IV CONTEXT FREE LANGUAGES 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 a s and b s. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 17

18 6. If S->aSb aab, A->bAa, A->ba.Find out the CFL Ans : S->aAb=>abab S->aSb=>a aab b =>a a ba b b(sub S->aAb) S->aSb =>a asb b =>a a aab b b=>a a a ba b bb Thus L={an bm am bn, where n,m>=1} 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;n 1} S Sbb S abb_ 9. Consider G whose productions are S aas_a, A SbA_SS ba. Show that S=>aabbaa S=>Aas =>asbas =>aabas =>aabbas =>aabbaa 10. Find the language generated by a CFG. G=({S},{0,1},{S 0 1 ε, S 0S0 1S1 S) S =>0S0 =>01S 10 =>0I0I0 S =>1S1 =>10S01 =>10001 Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 18

19 L= { w;w is a palindrome} Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 19

20 11. Differentiate sentences Vs sentential forms A sentence is a string of terminal symbols. A sentential form is a string containing a mix of variables and terminal symbols or all variables. This is an intermediate form in doing a derivation. 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 Stack or by reaching a final state. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 20

21 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 PDA s by empty stack. 16. 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}* } dle this language we need unlimited counting Capability. 17. Is it true the nondeterministic PDA is more powerful than that of deterministic PDA? justify your answer. Yes, wwr is accepted by NPDA but not any DPDA in the sense of language acceptance. 18. What is the additional feature of PDA has when compared with NFA? Is PDA superior over NFA? Is PDA superior over NFA in the 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. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 21

22 19. 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 memory. Pushdown Automata has a memory, which can be used to count the number. Pushdown Automata can accept context free languages. It is essentially an NFA with a stack. Acceptance of language. 20. A pushdown automata G=(Q,,G,d,q0,z,F) is said to be deterministic if 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 The first condition says that for any given input symbol most one 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 21. 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. 22. Is NPDA (Nondeterministic PDA) and DPDA (Deterministic PDA)equivalent? The languages accepted by NPDA and DPDA are not equivalent. For example: wwr is accepted by NPDA and not by any DPDA. 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. where L(M) = language accepted by PDA by reaching a final state. N(M) = language accepted by PDA by empty stack. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 22

23 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. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 23

24 FORMAL LANGUAGE AND AUTOMATA THEORY UNIT-V PROPERTIES OF CONTEXT FREE LANGUAGES 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. 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. (c) A regular language is also context free but not reverse True. (d)a regular language can be generated by two or more different grammar True. (e) Finite State machine (FSM) can recognize only regular grammar-true. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 24

25 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. 6. What are the closure properties of CFL? changes in 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 CFL s 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 9. Define Chomsky normal form. A grammar in which all productions are the form A BC or A α where A,B are variables and a is a terminal. 10. Define Grieback normal form? A grammar for which every productions is of the form A aα where A is a variable,a is a terminal and α is a string of variables. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 25

26 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) 12. what are the Properties of Context Free Languages? Let L 1 and L 2 be CFL s. (1) L 1 L 2 (the union) is CFL. (2) L 1 L 2 (the concatenation) is CFL. (3) L 1 * (the Kleene star) and L 1 + (the Kleene plus) are CFL. (4) L 1 R (the reversed language) is CFL. (5) L 1 L 2 (the intersection) is not necessarily CFL. (6) L 1 (the complement) is not necessarily CFL. 13. Definition for normal forms. There is two types of normal form. They are 1. Chomsky normal form(cnf) Eg :A->BC or A->a 2. Greiback normal form(gnf) Eg : A-> bc 14. Define unit production. A unit production is of the form A-> B, where A and B are variables. A unit production basically is a redundant production. Therefore we can eliminate the unit production by the following. Eg : A->B, then B->w then the solution is A->w. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 26

27 15. 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. 16. convert the following context free grammar to CNF. S-> AaBCb A-> abb B-> ac C-> acb/ac. S-> AA1 A1->A2A3 A2->a A3->BA1 A4->CA5 A5->b A->B1B2 B1->a B2->B3B4 B3->b B4->b B->C1C C1->a C->D1D2/E1E2 D1->a D2->CD3 D3->b E1->a E2->c 17. Define pumping lemma for CFL. Pumping lemma for CFl : let L be a CFl. Then there exists a constant n such that if z belongs to L with /z/ n, then we write z= uvwxy, subject to the following conditions. 1. /uvw/ n 2. Ux 18. What is a parser? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w,if w is a sentence of G or an error message indicating that w is not a sentence of G. 19. Define union of CFL. Let L1 be language recognized by G1 = (V1,T1,S1,P1) L2 be language recognized by G2 = (V2,T2,S2,P2) is L1 U L2 a context free language? yes. Just add the rule S S1/S2 But make sure that V1 V2 = 0 So formally G has V=V1 U V2 U V3 U {S} T = T1 U T2 P = P1 U P2 U { S S1/S2} Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 27

28 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. Differentiate sentences Vs sentential forms A sentence is a string of terminal symbols. A sentential form is a string containing a mix of variables and terminal symbols or all variables.this is an intermediate form in doing a derivation. 22. Find L(G) where G= ( {S},{0,1}, {S->0S1,S->Є },S ) S->Є, Є is in L(G) S-> 0S1 =>0Є1=>01 S->0S1=>0 0S11=>0011 Thus L(G)= { 0n1n n>=0}. 23. Decision properties of CFL. - Algorithm for CFL. - Converting PDA acceptance form. - Converting CFG to PDA - Converting PDA to CFG. - Eliminating useless symbols. - Eliminating unit production. - Eliminating - production. 24. 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. Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 28

29 25. What are(a) recursively enumerable languages (b) recursive sets? The languages that is accepted by TM is said to be recursively enumerable (r. e ) languages. Enumerable means that the strings in the language can be enumerated by the TM. The class of r. e languages include CFL s. The recursive sets include languages accepted by at least one TM that halts on all inputs. ************ALL THE BEST ********** Prepared by : A.MANI, AP/CSE/Chettinad college of Engg & Technology 29

UNIT 1 SNS COLLEGE OF ENGINEERING

UNIT 1 SNS COLLEGE OF ENGINEERING 1 SNS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING THEORY OF COMPUTATION TWO MARKS WITH ANSWERS UNIT 1 1. Define set. A set is a collection of objects. E.g.: The collection of

More information

JNTUWORLD. Code No: R

JNTUWORLD. Code No: R Code No: R09220504 R09 SET-1 B.Tech II Year - II Semester Examinations, April-May, 2012 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science and Engineering) Time: 3 hours Max. Marks: 75 Answer any five

More information

CT32 COMPUTER NETWORKS DEC 2015

CT32 COMPUTER NETWORKS DEC 2015 Q.2 a. Using the principle of mathematical induction, prove that (10 (2n-1) +1) is divisible by 11 for all n N (8) Let P(n): (10 (2n-1) +1) is divisible by 11 For n = 1, the given expression becomes (10

More information

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

R10 SET a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? R1 SET - 1 1. a) Construct a DFA that accepts an identifier of a C programming language. b) Differentiate between NFA and DFA? 2. a) Design a DFA that accepts the language over = {, 1} of all strings that

More information

Multiple Choice Questions

Multiple Choice Questions Techno India Batanagar Computer Science and Engineering Model Questions Subject Name: Formal Language and Automata Theory Subject Code: CS 402 Multiple Choice Questions 1. The basic limitation of an FSM

More information

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

Skyup's Media. PART-B 2) Construct a Mealy machine which is equivalent to the Moore machine given in table. Code No: XXXXX JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY, HYDERABAD B.Tech II Year I Semester Examinations (Common to CSE and IT) Note: This question paper contains two parts A and B. Part A is compulsory

More information

QUESTION BANK. Unit 1. Introduction to Finite Automata

QUESTION BANK. Unit 1. Introduction to Finite Automata QUESTION BANK 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

More information

UNIT I PART A PART B

UNIT I PART A PART B OXFORD ENGINEERING COLLEGE (NAAC ACCREDITED WITH B GRADE) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS YEAR/SEM: III/V STAFF NAME: Dr. Sangeetha Senthilkumar SUB.CODE: CS6503 SUB.NAME:

More information

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

QUESTION BANK. Formal Languages and Automata Theory(10CS56) QUESTION BANK Formal Languages and Automata Theory(10CS56) Chapter 1 1. Define the following terms & explain with examples. i) Grammar ii) Language 2. Mention the difference between DFA, NFA and εnfa.

More information

(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

(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 Code No: R05310501 Set No. 1 III B.Tech I Semester Regular Examinations, November 2008 FORMAL LANGUAGES AND AUTOMATA THEORY (Computer Science & Engineering) Time: 3 hours Max Marks: 80 Answer any FIVE

More information

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : III Year, V Semester Section : CSE - 1 & 2 Subject Code : CS6503 Subject

More information

Final Course Review. Reading: Chapters 1-9

Final Course Review. Reading: Chapters 1-9 Final Course Review Reading: Chapters 1-9 1 Objectives Introduce concepts in automata theory and theory of computation Identify different formal language classes and their relationships Design grammars

More information

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

CS210 THEORY OF COMPUTATION QUESTION BANK PART -A UNIT- I CS210 THEORY OF COMPUTATION QUESTION BANK PART -A UNIT- I 1) Is it true that the language accepted by any NDFA is different from the regular language? Justify your answer. 2) Describe the following sets

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS6503 / THEORY OF COMPUTATION III YEAR / V SEM QUESTION BANK UNIT I AUTOMATA

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS6503 / THEORY OF COMPUTATION III YEAR / V SEM QUESTION BANK UNIT I AUTOMATA DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS6503 / THEORY OF COMPUTATION III YEAR / V SEM QUESTION BANK UNIT I AUTOMATA 1. Why are switching circuits called as finite state systems? A switching circuit

More information

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

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata Solved Subjective From Midterm Papers Dec 07,2012 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 MIDTERM SPRING 2012 Q. Point of Kleen Theory. Answer:- (Page 25) 1. If a language can be accepted

More information

Ambiguous Grammars and Compactification

Ambiguous Grammars and Compactification Ambiguous Grammars and Compactification Mridul Aanjaneya Stanford University July 17, 2012 Mridul Aanjaneya Automata Theory 1/ 44 Midterm Review Mathematical Induction and Pigeonhole Principle Finite Automata

More information

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

T.E. (Computer Engineering) (Semester I) Examination, 2013 THEORY OF COMPUTATION (2008 Course) *4459255* [4459] 255 Seat No. T.E. (Computer Engineering) (Semester I) Examination, 2013 THEY OF COMPUTATION (2008 Course) Time : 3 Hours Max. Marks : 100 Instructions : 1) Answers to the two Sections

More information

Languages and Compilers

Languages and Compilers Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 3. Formal Languages, Grammars and Automata Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office:

More information

AUTOMATA THEORY AND COMPUTABILITY

AUTOMATA THEORY AND COMPUTABILITY AUTOMATA THEORY AND COMPUTABILITY QUESTION BANK Module 1 : Introduction to theory of computation and FSM Objective: Upon the completion of this chapter you will be able to Define Finite automata, Basic

More information

Regular Languages and Regular Expressions

Regular Languages and Regular Expressions Regular Languages and Regular Expressions According to our definition, a language is regular if there exists a finite state automaton that accepts it. Therefore every regular language can be described

More information

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur Finite Automata Dr. Nadeem Akhtar Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur PhD Laboratory IRISA-UBS University of South Brittany European University

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016 Lecture 15 Ana Bove May 23rd 2016 More on Turing machines; Summary of the course. Overview of today s lecture: Recap: PDA, TM Push-down

More information

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

1. Which of the following regular expressions over {0, 1} denotes the set of all strings not containing 100 as a sub-string? Multiple choice type questions. Which of the following regular expressions over {, } denotes the set of all strings not containing as a sub-string? 2. DFA has a) *(*)* b) ** c) ** d) *(+)* a) single final

More information

Formal Languages and Automata

Formal Languages and Automata Mobile Computing and Software Engineering p. 1/3 Formal Languages and Automata Chapter 3 Regular languages and Regular Grammars Chuan-Ming Liu cmliu@csie.ntut.edu.tw Department of Computer Science and

More information

Decision Properties for Context-free Languages

Decision Properties for Context-free Languages Previously: Decision Properties for Context-free Languages CMPU 240 Language Theory and Computation Fall 2018 Context-free languages Pumping Lemma for CFLs Closure properties for CFLs Today: Assignment

More information

ECS 120 Lesson 7 Regular Expressions, Pt. 1

ECS 120 Lesson 7 Regular Expressions, Pt. 1 ECS 120 Lesson 7 Regular Expressions, Pt. 1 Oliver Kreylos Friday, April 13th, 2001 1 Outline Thus far, we have been discussing one way to specify a (regular) language: Giving a machine that reads a word

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! [ALSU03] Chapter 3 - Lexical Analysis Sections 3.1-3.4, 3.6-3.7! Reading for next time [ALSU03] Chapter 3 Copyright (c) 2010 Ioanna

More information

Compiler Construction

Compiler Construction Compiler Construction Exercises 1 Review of some Topics in Formal Languages 1. (a) Prove that two words x, y commute (i.e., satisfy xy = yx) if and only if there exists a word w such that x = w m, y =

More information

Models of Computation II: Grammars and Pushdown Automata

Models of Computation II: Grammars and Pushdown Automata Models of Computation II: Grammars and Pushdown Automata COMP1600 / COMP6260 Dirk Pattinson Australian National University Semester 2, 2018 Catch Up / Drop in Lab Session 1 Monday 1100-1200 at Room 2.41

More information

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

CS5371 Theory of Computation. Lecture 8: Automata Theory VI (PDA, PDA = CFG) CS5371 Theory of Computation Lecture 8: Automata Theory VI (PDA, PDA = CFG) Objectives Introduce Pushdown Automaton (PDA) Show that PDA = CFG In terms of descriptive power Pushdown Automaton (PDA) Roughly

More information

AUBER (Models of Computation, Languages and Automata) EXERCISES

AUBER (Models of Computation, Languages and Automata) EXERCISES 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

More information

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

Closure Properties of CFLs; Introducing TMs. CS154 Chris Pollett Apr 9, 2007. Closure Properties of CFLs; Introducing TMs CS154 Chris Pollett Apr 9, 2007. Outline Closure Properties of Context Free Languages Algorithms for CFLs Introducing Turing Machines Closure Properties of CFL

More information

Introduction to Automata Theory

Introduction to Automata Theory Introduction to Automata Theory Automata theory is basically about the study of different mechanisms for generation and recognition of languages. Automata theory is basically for the study of different

More information

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

Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5 Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5 1 Not all languages are regular So what happens to the languages which are not regular? Can we still come up with a language recognizer?

More information

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

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np Chapter 1: Introduction Introduction Purpose of the Theory of Computation: Develop formal mathematical models of computation that reflect real-world computers. Nowadays, the Theory of Computation can be

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 11 Ana Bove April 26th 2018 Recap: Regular Languages Decision properties of RL: Is it empty? Does it contain this word? Contains

More information

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

Derivations of a CFG. MACM 300 Formal Languages and Automata. Context-free Grammars. Derivations and parse trees Derivations of a CFG MACM 300 Formal Languages and Automata Anoop Sarkar http://www.cs.sfu.ca/~anoop strings grow on trees strings grow on Noun strings grow Object strings Verb Object Noun Verb Object

More information

REGULAR EXPRESSIONS AND LANGUAGES

REGULAR EXPRESSIONS AND LANGUAGES CS2303 THEORY OF COMPUTATION AIM To have a introductory knowledge of automata, formal language theory and computability. OBJECTIVES UNIT I To have an understanding of finite state and pushdown automata.

More information

Theory of Computation, Homework 3 Sample Solution

Theory of Computation, Homework 3 Sample Solution Theory of Computation, Homework 3 Sample Solution 3.8 b.) The following machine M will do: M = "On input string : 1. Scan the tape and mark the first 1 which has not been marked. If no unmarked 1 is found,

More information

Learn Smart and Grow with world

Learn Smart and Grow with world Learn Smart and Grow with world All Department Smart Study Materials Available Smartkalvi.com TABLE OF CONTENTS S.No DATE TOPIC PAGE NO. UNIT-I FINITE AUTOMATA 1 Introduction 1 2 Basic Mathematical Notation

More information

CS402 - Theory of Automata Glossary By

CS402 - Theory of Automata Glossary By CS402 - Theory of Automata Glossary By Acyclic Graph : A directed graph is said to be acyclic if it contains no cycles. Algorithm : A detailed and unambiguous sequence of instructions that describes how

More information

Context Free Languages and Pushdown Automata

Context Free Languages and Pushdown Automata Context Free Languages and Pushdown Automata COMP2600 Formal Methods for Software Engineering Ranald Clouston Australian National University Semester 2, 2013 COMP 2600 Context Free Languages and Pushdown

More information

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

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR-621113 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Third Year CSE( Sem:V) CS2303- THEORY OF COMPUTATION PART B-16

More information

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Theory of Computation Dr. Weiss Extra Practice Exam Solutions Name: of 7 Theory of Computation Dr. Weiss Extra Practice Exam Solutions Directions: Answer the questions as well as you can. Partial credit will be given, so show your work where appropriate. Try to be

More information

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata Formal Languages and Compilers Lecture IV: Regular Languages and Finite Automata Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/

More information

Actually talking about Turing machines this time

Actually talking about Turing machines this time Actually talking about Turing machines this time 10/25/17 (Using slides adapted from the book) Administrivia HW due now (Pumping lemma for context-free languages) HW due Friday (Building TMs) Exam 2 out

More information

CS402 - Theory of Automata FAQs By

CS402 - Theory of Automata FAQs By CS402 - Theory of Automata FAQs By Define the main formula of Regular expressions? Define the back ground of regular expression? Regular expressions are a notation that you can think of similar to a programming

More information

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA TABLE OF CONTENTS SNo DATE TOPIC PAGE NO UNIT-I FINITE AUTOMATA 1 Introduction 1 2 Basic Mathematical Notation Techniques 3 3 Finite State systems 4 4 Basic Definitions 6 5 Finite Automaton 7 6 DFA NDFA

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2017 http://cseweb.ucsd.edu/classes/sp17/cse105-ab/ Today's learning goals Sipser Ch 1.2, 1.3 Design NFA recognizing a given language Convert an NFA (with or without

More information

DVA337 HT17 - LECTURE 4. Languages and regular expressions

DVA337 HT17 - LECTURE 4. Languages and regular expressions DVA337 HT17 - LECTURE 4 Languages and regular expressions 1 SO FAR 2 TODAY Formal definition of languages in terms of strings Operations on strings and languages Definition of regular expressions Meaning

More information

Theory of Computation

Theory of Computation Theory of Computation For Computer Science & Information Technology By www.thegateacademy.com Syllabus Syllabus for Theory of Computation Regular Expressions and Finite Automata, Context-Free Grammar s

More information

Limits of Computation p.1/?? Limits of Computation p.2/??

Limits of Computation p.1/?? Limits of Computation p.2/?? Context-Free Grammars (CFG) There are languages, such as {0 n 1 n n 0} that cannot be described (specified) by finite automata or regular expressions. Context-free grammars provide a more powerful mechanism

More information

Question Bank. 10CS63:Compiler Design

Question Bank. 10CS63:Compiler Design Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a

More information

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

University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 University of Nevada, Las Vegas Computer Science 456/656 Fall 2016 The entire examination is 925 points. The real final will be much shorter. Name: No books, notes, scratch paper, or calculators. Use pen

More information

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES Thesis submitted in partial fulfillment of the requirements for the award of degree of Master of Engineering in Computer Science and Engineering Submitted

More information

ECS 120 Lesson 16 Turing Machines, Pt. 2

ECS 120 Lesson 16 Turing Machines, Pt. 2 ECS 120 Lesson 16 Turing Machines, Pt. 2 Oliver Kreylos Friday, May 4th, 2001 In the last lesson, we looked at Turing Machines, their differences to finite state machines and pushdown automata, and their

More information

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars

Where We Are. CMSC 330: Organization of Programming Languages. This Lecture. Programming Languages. Motivation for Grammars CMSC 330: Organization of Programming Languages Context Free Grammars Where We Are Programming languages Ruby OCaml Implementing programming languages Scanner Uses regular expressions Finite automata Parser

More information

Formal Languages and Compilers Lecture VI: Lexical Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis Formal Languages and Compilers Lecture VI: Lexical Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Formal

More information

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

CS/B.Tech/CSE/IT/EVEN/SEM-4/CS-402/ ItIauIafIaAblll~AladUnrtel1ity CS/B.Tech/CSE/IT/EVEN/SEM-4/CS-402/2015-16 ItIauIafIaAblll~AladUnrtel1ity ~ t; ~~ ) MAULANA ABUL KALAM AZAD UNIVERSITY OF TECHNOLOGY, WEST BENGAL Paper Code: CS-402 FORMAL LANGUAGE AND AUTOMATA THEORY

More information

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

1. [5 points each] True or False. If the question is currently open, write O or Open. University of Nevada, Las Vegas Computer Science 456/656 Spring 2018 Practice for the Final on May 9, 2018 The entire examination is 775 points. The real final will be much shorter. Name: No books, notes,

More information

Reflection in the Chomsky Hierarchy

Reflection in the Chomsky Hierarchy Reflection in the Chomsky Hierarchy Henk Barendregt Venanzio Capretta Dexter Kozen 1 Introduction We investigate which classes of formal languages in the Chomsky hierarchy are reflexive, that is, contain

More information

Introduction to Syntax Analysis

Introduction to Syntax Analysis Compiler Design 1 Introduction to Syntax Analysis Compiler Design 2 Syntax Analysis The syntactic or the structural correctness of a program is checked during the syntax analysis phase of compilation.

More information

COP 3402 Systems Software Syntax Analysis (Parser)

COP 3402 Systems Software Syntax Analysis (Parser) COP 3402 Systems Software Syntax Analysis (Parser) Syntax Analysis 1 Outline 1. Definition of Parsing 2. Context Free Grammars 3. Ambiguous/Unambiguous Grammars Syntax Analysis 2 Lexical and Syntax Analysis

More information

Theory and Compiling COMP360

Theory and Compiling COMP360 Theory and Compiling COMP360 It has been said that man is a rational animal. All my life I have been searching for evidence which could support this. Bertrand Russell Reading Read sections 2.1 3.2 in the

More information

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

MIT Specifying Languages with Regular Expressions and Context-Free Grammars MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology Language Definition Problem How to precisely

More information

LECTURE NOTES THEORY OF COMPUTATION

LECTURE NOTES THEORY OF COMPUTATION LECTURE NOTES ON THEORY OF COMPUTATION P Anjaiah Assistant Professor Ms. B Ramyasree Assistant Professor Ms. E Umashankari Assistant Professor Ms. A Jayanthi Assistant Professor INSTITUTE OF AERONAUTICAL

More information

Decision, Computation and Language

Decision, Computation and Language Decision, Computation and Language Regular Expressions Dr. Muhammad S Khan (mskhan@liv.ac.uk) Ashton Building, Room G22 http://www.csc.liv.ac.uk/~khan/comp218 Regular expressions M S Khan (Univ. of Liverpool)

More information

Introduction to Syntax Analysis. The Second Phase of Front-End

Introduction to Syntax Analysis. The Second Phase of Front-End Compiler Design IIIT Kalyani, WB 1 Introduction to Syntax Analysis The Second Phase of Front-End Compiler Design IIIT Kalyani, WB 2 Syntax Analysis The syntactic or the structural correctness of a program

More information

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology MIT 6.035 Specifying Languages with Regular essions and Context-Free Grammars Martin Rinard Massachusetts Institute of Technology Language Definition Problem How to precisely define language Layered structure

More information

Parsing. source code. while (k<=n) {sum = sum+k; k=k+1;}

Parsing. source code. while (k<=n) {sum = sum+k; k=k+1;} Compiler Construction Grammars Parsing source code scanner tokens regular expressions lexical analysis Lennart Andersson parser context free grammar Revision 2012 01 23 2012 parse tree AST builder (implicit)

More information

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA.

PS3 - Comments. Describe precisely the language accepted by this nondeterministic PDA. University of Virginia - cs3102: Theory of Computation Spring 2010 PS3 - Comments Average: 46.6 (full credit for each question is 55 points) Problem 1: Mystery Language. (Average 8.5 / 10) In Class 7,

More information

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

KHALID PERVEZ (MBA+MCS) CHICHAWATNI FAQ's about Lectures 1 to 5 QNo1.What is the difference between the strings and the words of a language? A string is any combination of the letters of an alphabet where as the words of a language are the

More information

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

Decidable Problems. We examine the problems for which there is an algorithm. Decidable Problems We examine the problems for which there is an algorithm. Decidable Problems A problem asks a yes/no question about some input. The problem is decidable if there is a program that always

More information

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters : Organization of Programming Languages Context Free Grammars 1 Architecture of Compilers, Interpreters Source Scanner Parser Static Analyzer Intermediate Representation Front End Back End Compiler / Interpreter

More information

Formal languages and computation models

Formal languages and computation models Formal languages and computation models Guy Perrier Bibliography John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman - Introduction to Automata Theory, Languages, and Computation - Addison Wesley, 2006.

More information

LECTURE NOTES THEORY OF COMPUTATION

LECTURE NOTES THEORY OF COMPUTATION LECTURE NOTES ON THEORY OF COMPUTATION Dr. K Rajendra Prasad Professor Ms. N Mamtha Assistant Professor Ms. S Swarajya Lakshmi Assistant Professor Mr. D Abdulla Assistant Professor INSTITUTE OF AERONAUTICAL

More information

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

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81% Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81% 1. (2 pts) See text. You can t be sloppy defining terms like this. You must show a bijection between the natural numbers

More information

Part 5 Program Analysis Principles and Techniques

Part 5 Program Analysis Principles and Techniques 1 Part 5 Program Analysis Principles and Techniques Front end 2 source code scanner tokens parser il errors Responsibilities: Recognize legal programs Report errors Produce il Preliminary storage map Shape

More information

Chapter 14: Pushdown Automata

Chapter 14: Pushdown Automata Chapter 14: Pushdown Automata Peter Cappello Department of Computer Science University of California, Santa Barbara Santa Barbara, CA 93106 cappello@cs.ucsb.edu The corresponding textbook chapter should

More information

Chapter Seven: Regular Expressions

Chapter Seven: Regular Expressions Chapter Seven: Regular Expressions Regular Expressions We have seen that DFAs and NFAs have equal definitional power. It turns out that regular expressions also have exactly that same definitional power:

More information

PDA s. and Formal Languages. Automata Theory CS 573. Outline of equivalence of PDA s and CFG s. (see Theorem 5.3)

PDA s. and Formal Languages. Automata Theory CS 573. Outline of equivalence of PDA s and CFG s. (see Theorem 5.3) CS 573 Automata Theory and Formal Languages Professor Leslie Lander Lecture # 20 November 13, 2000 Greibach Normal Form (GNF) Sheila Greibach s normal form (GNF) for a CFG is one where EVERY production

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

Context-Free Languages and Parse Trees

Context-Free Languages and Parse Trees Context-Free Languages and Parse Trees Mridul Aanjaneya Stanford University July 12, 2012 Mridul Aanjaneya Automata Theory 1/ 41 Context-Free Grammars A context-free grammar is a notation for describing

More information

CS 314 Principles of Programming Languages. Lecture 3

CS 314 Principles of Programming Languages. Lecture 3 CS 314 Principles of Programming Languages Lecture 3 Zheng Zhang Department of Computer Science Rutgers University Wednesday 14 th September, 2016 Zheng Zhang 1 CS@Rutgers University Class Information

More information

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino

3. Syntax Analysis. Andrea Polini. Formal Languages and Compilers Master in Computer Science University of Camerino 3. Syntax Analysis Andrea Polini Formal Languages and Compilers Master in Computer Science University of Camerino (Formal Languages and Compilers) 3. Syntax Analysis CS@UNICAM 1 / 54 Syntax Analysis: the

More information

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

Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata Lexical Analysis Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata Phase Ordering of Front-Ends Lexical analysis (lexer) Break input string

More information

Nondeterministic Finite Automata (NFA): Nondeterministic Finite Automata (NFA) states of an automaton of this kind may or may not have a transition for each symbol in the alphabet, or can even have multiple

More information

Turing Machine Languages

Turing Machine Languages Turing Machine Languages Based on Chapters 23-24-25 of (Cohen 1997) Introduction A language L over alphabet is called recursively enumerable (r.e.) if there is a Turing Machine T that accepts every word

More information

Outline. Language Hierarchy

Outline. Language Hierarchy Outline Language Hierarchy Definition of Turing Machine TM Variants and Equivalence Decidability Reducibility Language Hierarchy Regular: finite memory CFG/PDA: infinite memory but in stack space TM: infinite

More information

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,, CMPSCI 601: Recall From Last Time Lecture 5 Definition: A context-free grammar (CFG) is a 4- tuple, variables = nonterminals, terminals, rules = productions,,, are all finite. 1 ( ) $ Pumping Lemma for

More information

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION CSE 105 THEORY OF COMPUTATION Spring 2016 http://cseweb.ucsd.edu/classes/sp16/cse105-ab/ Today's learning goals Sipser Ch 3.2, 3.3 Define variants of TMs Enumerators Multi-tape TMs Nondeterministic TMs

More information

Lexical Analysis. Prof. James L. Frankel Harvard University

Lexical Analysis. Prof. James L. Frankel Harvard University Lexical Analysis Prof. James L. Frankel Harvard University Version of 5:37 PM 30-Jan-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Regular Expression Notation We will develop a

More information

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End

Architecture of Compilers, Interpreters. CMSC 330: Organization of Programming Languages. Front End Scanner and Parser. Implementing the Front End Architecture of Compilers, Interpreters : Organization of Programming Languages ource Analyzer Optimizer Code Generator Context Free Grammars Intermediate Representation Front End Back End Compiler / Interpreter

More information

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

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions Last lecture CMSC330 Finite Automata Languages Sets of strings Operations on languages Regular expressions Constants Operators Precedence 1 2 Finite automata States Transitions Examples Types This lecture

More information

UNIT -2 LEXICAL ANALYSIS

UNIT -2 LEXICAL ANALYSIS OVER VIEW OF LEXICAL ANALYSIS UNIT -2 LEXICAL ANALYSIS o To identify the tokens we need some method of describing the possible tokens that can appear in the input stream. For this purpose we introduce

More information

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

I have read and understand all of the instructions below, and I will obey the Academic Honor Code. Midterm Exam CS 341-451: Foundations of Computer Science II Fall 2014, elearning section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all

More information

CSCI 340: Computational Models. Turing Machines. Department of Computer Science

CSCI 340: Computational Models. Turing Machines. Department of Computer Science CSCI 340: Computational Models Turing Machines Chapter 19 Department of Computer Science The Turing Machine Regular Expressions Acceptor: FA, TG Nondeterminism equal? Yes Closed Under: L 1 + L 2 L 1 L

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Context Free Grammars and Parsing 1 Recall: Architecture of Compilers, Interpreters Source Parser Static Analyzer Intermediate Representation Front End Back

More information

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject.

Turing Machines. A transducer is a finite state machine (FST) whose output is a string and not just accept or reject. Turing Machines Transducers: A transducer is a finite state machine (FST) whose output is a string and not just accept or reject. Each transition of an FST is labeled with two symbols, one designating

More information

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama

Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama Midterm Exam II CIS 341: Foundations of Computer Science II Spring 2006, day section Prof. Marvin K. Nakayama Print family (or last) name: Print given (or first) name: I have read and understand all of

More information