DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Size: px
Start display at page:

Download "DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING"

Transcription

1 CS6503 THEORY OF COMPUTATION L T P C OBJECTIVES: The student should be made to: Understand various Computing models like Finite State Machine, Pushdown Automata, and Turing Machine. Be aware of Decidability and Un-decidability of various problems. Learn types of grammars. UNIT I FINITE AUTOMATA 9 Introduction- Basic Mathematical Notation and techniques- Finite State systems Basic Definitions Finite Automaton DFA & NDFA Finite Automaton with - moves Regular Languages- Regular Expression Equivalence of NFA and DFA Equivalence of NDFA s with and without -moves Equivalence of finite Automaton and regular expressions Minimization of DFA- - Pumping Lemma for Regular sets Problems based on Pumping Lemma. UNIT II GRAMMARS 9 Grammar Introduction Types of Grammar - Context Free Grammars and Languages Derivations and Languages Ambiguity- Relationship between derivation and derivation trees Simplification of CFG Elimination of Useless symbols - Unit productions - Null productions Greiback Normal form Chomsky normal form Problems related to CNF and GNF. UNIT III PUSHDOWN AUTOMATA 9 Pushdown Automata- Definitions Moves Instantaneous descriptions Deterministic pushdown automata Equivalence of Pushdown automata and CFL - pumping lemma for CFL problems based on pumping Lemma. UNIT IV TURING MACHINES 9 Definitions of Turing machines Models Computable languages and functions Techniques for Turing machine construction Multi head and Multi tape Turing Machines - The Halting problem Partial Solvability Problems about Turing machine- Chomskian hierarchy of languages. UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS 9 Unsolvable Problems and Computable Functions Primitive recursive functions Recursive and recursively enumerable languages Universal Turing machine. MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable problems- Tractable and possibly intractable problems - P and NP completeness - Polynomial time reductions. TOTAL: 45 PERIODS OUTCOMES: At the end of the course, the student should be able to: Design Finite State Machine, Pushdown Automata, and Turing Machine. Explain the Decidability or Undecidability of various problems TEXT BOOKS: 1. Hopcroft J.E., Motwani R. and Ullman J.D, Introduction to Automata Theory, Languages and Computations, Second Edition, Pearson Education, (UNIT 1,2,3) 2. John C Martin, Introduction to Languages and the Theory of Computation, Third Edition, Tata McGraw Hill Publishing Company, New Delhi, (UNIT 4,5) REFERENCES: 1. Mishra K L P and Chandrasekaran N, Theory of Computer Science - Automata, Languages and Computation, Third Edition, Prentice Hall of India, Harry R Lewis and Christos H Papadimitriou, Elements of the Theory of Computation, Second Edition, Prentice Hall of India, Pearson Education, New Delhi, Peter Linz, An Introduction to Formal Language and Automata, Third Edition, Narosa Publishers, New Delhi, Kamala Krithivasan and Rama. R, Introduction to Formal Languages, Automata Theory and Computation, Pearson Education 2009

2 UNIT-I FINITE AUTOMATA

3 UNIT I FINITE AUTOMATA Introduction- Basic Mathematical Notation and techniques- Finite State systems Basic Definitions Finite Automaton DFA & NDFA Finite Automaton with - moves Regular Languages- Regular Expression Equivalence of NFA and DFA Equivalence of NDFA s with and without -moves Equivalence of finite Automaton and regular expressions Minimization of DFA- Pumping Lemma for Regular sets Problems based on Pumping Lemma. Introduction- Basic Mathematical Notation

4

5

6

7 Proof Techniques

8

9

10

11

12 Finite Automata

13

14 Finite Automata Model

15

16 What does an FA DO?

17

18 Deterministic Finite Automata

19

20 Constructing a DFA Example:

21 Example DFA NON DETERMINISTIC FINITE AUTOMATA

22 EXAMPLE EXAMPLES OF NFA

23 NFA with ε Closure

24 Another Example

25 Theorem

26

27

28

29

30

31

32

33

34 Constructing NFA for regular expressions Find a regular expression for a DFA

35 Pumping Lemma

36 1. Prove { 0 i 1 i i>= 0} is not regular. 2. Prove {1 i i is prime} is not regular.

37 UNIT-II GRAMMERS

38 UNIT II GRAMMARS Grammar Introduction Types of Grammar Context Free Grammars and Languages Derivations and Languages Ambiguity- Relationship between derivation and derivation trees Simplification of CFG Elimination of Useless symbols Unit productions Null productions Greiback Normal form Chomsky normal form Problems related to CNF and GNF. CONTEXT FREE GRAMMAR Definition A context-free grammar (CFG) consisting of a finite set of grammar rules is a quadruple (N, T, P, S) where N is a set of non-terminal symbols. T is a set of terminals where N T = NULL. P is a set of rules, P: N (N T) *, i.e., the left-hand side of the production rule P does have any right context or left context. S is the start symbol. Example The grammar ({A}, {a, b, c}, P, A), P : A aa, A abc. The grammar ({S, a, b}, {a, b}, P, S), P: S asa, S bsb, S ε The grammar ({S, F}, {0, 1}, P, S), P: S 00S 11F, F 00F ε Generation of Derivation Tree A derivation tree or parse tree is an ordered rooted tree that graphically represents the semantic information a string derived from a context-free grammar. Representation Technique Root vertex Must be labeled by the start symbol. Vertex Labeled by a non-terminal symbol.

39 Leaves Labeled by a terminal symbol or ε. If S x 1 x 2 x n is a production rule in a CFG, then the parse tree / derivation tree will be as follows There are two different approaches to draw a derivation tree Top-down Approach Starts with the starting symbol S Goes down to tree leaves using productions Bottom-up Approach Starts from tree leaves Proceeds upward to the root which is the starting symbol S Derivation or Yield of a Tree The derivation or the yield of a parse tree is the final string obtained by concatenating the labels of the leaves of the tree from left to right, ignoring the Nulls. However, if all the leaves are Null, derivation is Null. Example Let a CFG {N,T,P,S} be N = {S}, T = {a, b}, Starting symbol = S, P = S SS asb ε One derivation from the above CFG is abaabb S SS asbs abs abasb abaasbb abaabb

40 Sentential Form and Partial Derivation Tree A partial derivation tree is a sub-tree of a derivation tree/parse tree such that either all of its children are in the sub-tree or none of them are in the sub-tree. Example If in any CFG the productions are S AB, A aaa ε, B Bb ε the partial derivation tree can be the following If a partial derivation tree contains the root S, it is called a sentential form. The above subtree is also in sentential form. Leftmost and Rightmost Derivation of a String Example Leftmost derivation A leftmost derivation is obtained by applying production to the leftmost variable in each step. Rightmost derivation A rightmost derivation is obtained by applying production to the rightmost variable in each step.

41 Let any set of production rules in a CFG be X X+X X*X X a over an alphabet {a}. The leftmost derivation for the string "a+a*a" may be X X+X a+x a+ X*X a+a*x a+a*a The rightmost derivation for the above string "a+a*a" may be X X*X X*a X+X*a X+a*a a+a*a The stepwise derivation of the above string is shown as below Left and Right Recursive Grammars In a context-free grammar G, if there is a production in the form X Xa wherex is a non-terminal and a is a string of terminals, it is called a left recursive production. The grammar having a left recursive production is called a left recursive grammar. And if in a context-free grammar G, if there is a production is in the form X ax where X is a non-terminal and a is a string of terminals, it is called a right recursive production. The grammar having a right recursive production is called a right recursive grammar. Example The sentence ( a + b ) * c has a unique leftmost derivation, a unique (different) rightmost derivation and the unique parse tree shown below: Parse Tree: ( a + b ) * c E / \ E * E / \ \ ( E ) c E / \ / \ / \ / \

42 / \ E + E a b / \ E E / \ / \ / E \ / / \ \ / \ E E ( a + b )* c AMBIGUITY If a context free grammar G has more than one derivation tree for some stringw L(G), it is called an ambiguous grammar. There exist multiple right-most or left-most derivations for some string generated from that grammar. Problem Check whether the grammar G with production rules X X+X X*X X a is ambiguous or not. Solution Let s find out the derivation tree for the string "a+a*a". It has two leftmost derivations. Derivation 1 X X+X a +X a+ X*X a+a*x a+a*a Parse tree 1

43 Derivation 2 X X*X X+X*X a+ X*X a+a*x a+a*a Parse tree 2 As there are two parse trees for a single string "a+a*a", the grammar G is ambiguous. For example, the very simple sentence a + b * c. The table looks at leftmost derivations and parse trees: 1st Leftmost Der. E ===> E + E ===> a + E ===> a + E * E 2nd Leftmost Der. E ===> E * E ===> E + E * E ===> a + E * E

44 ===> a + b * E ===> a + b * c 1st Parse Tree E / \ / \ E + E / \ / \ a E * E b c ===> a + b * E ===> a + b * c 2nd Parse Tree E / \ / \ E * E / \ / \ E + E c a b For example, the above sentence a + b * c that caused a problem has the following leftmost derivation and parse tree on the left (along with the its twin a * b + c on the right): Leftmost Derivations a + b * c E ===> E + T ===> T + T ===> F + T ===> a + T ===> a + T * F ===> a + F * F ===> a + b * F ===> a + b * c 1st Parse Tree E / \ a * b + c E ===> E + T ===> T + T ===> T * F + T ===> F * F + T ===> a * F + T ===> a * b + T ===> a * b + F ===> a * b + c 2nd Parse Tree E / \

45 / \ E + T / \ T T * F F F c a b / \ E + T T F / \ / \ c T * F F b a SIMPLIFICATION OF CFG In a CFG, it may happen that all the production rules and symbols are not needed for the derivation of strings. Besides, there may be some null productions and unit productions. Elimination of these productions and symbols is called simplification of CFGs. Simplification essentially comprises of the following steps Reduction of CFG Removal of Unit Productions Removal of Null Productions Reduction of CFG CFGs are reduced in two phases Phase 1 Derivation of an equivalent grammar, G, from the CFG, G, such that each variable derives some terminal string. Derivation Procedure Step 1 Include all symbols, W 1, that derive some terminal and initialize i=1. Step 2 Include all symbols, W i+1, that derive W i. Step 3 Increment i and repeat Step 2, until W i+1 = W i.

46 Step 4 Include all production rules that have W i in it. Phase 2 Derivation of an equivalent grammar, G, from the CFG, G, such that each symbol appears in a sentential form. Derivation Procedure Step 1 Include the start symbol in Y 1 and initialize i = 1. Step 2 Include all symbols, Y i+1, that can be derived from Y i and include all production rules that have been applied. Step 3 Increment i and repeat Step 2, until Y i+1 = Y i. Problem Find a reduced grammar equivalent to the grammar G, having production rules, P: S AC B, A a, C c BC, E aa e Solution Phase 1 T = { a, c, e } W 1 = { A, C, E } from rules A a, C c and E aa W 2 = { A, C, E } { S } from rule S AC W 3 = { A, C, E, S } Since W 2 = W 3, we can derive G as G = { { A, C, E, S }, { a, c, e }, P, {S}} where P: S AC, A a, C c, E aa e Phase 2 Y 1 = { S } Y 2 = { S, A, C } from rule S AC Y 3 = { S, A, C, a, c } from rules A a and C c Y 4 = { S, A, C, a, c } Since Y 3 = Y 4, we can derive G as G = { { A, C, S }, { a, c }, P, {S}} where P: S AC, A a, C c

47 Removal of Unit Productions Any production rule in the form A B where A, B Non-terminal is called unit production. Removal Procedure Step 1 To remove A B, add production A x to the grammar rule wheneverb x occurs in the grammar. [x Terminal, x can be Null] Step 2 Delete A B from the grammar. Step 3 Repeat from step 1 until all unit productions are removed. Problem Remove unit production from the following S XY, X a, Y Z b, Z M, M N, N a Solution There are 3 unit productions in the grammar Y Z, Z M, and M N At first, we will remove M N. As N a, we add M a, and M N is removed. The production set becomes S XY, X a, Y Z b, Z M, M a, N a Now we will remove Z M. As M a, we add Z a, and Z M is removed. The production set becomes S XY, X a, Y Z b, Z a, M a, N a Now we will remove Y Z. As Z a, we add Y a, and Y Z is removed. The production set becomes S XY, X a, Y a b, Z a, M a, N a Now Z, M, and N are unreachable, hence we can remove those. The final CFG is unit production free S XY, X a, Y a b

48 Removal of Null Productions In a CFG, a non-terminal symbol A is a nullable variable if there is a production A ε or there is a derivation that starts at A and finally ends up with ε: A... ε Removal Procedure Step 1 Find out nullable non-terminal variables which derive. Step 2 Step 3 For each production A a, construct all productions A x where x is obtained from a by removing one or multiple non-terminals from Step 1. Combine the original productions with the result of step 2 and remove productions. Problem Remove null production from the following S ASA ab b, A B, B b Solution There are two nullable variables A and B At first, we will remove B ε. After removing B ε, the production set becomes S ASA ab b a, A B b, B b Now we will remove A ε. After removing A ε, the production set becomes S ASA ab b a SA AS S, A B b, B b This is the final production set without null transition. CHOMSKY NORMAL FORM A CFG is in Chomsky Normal Form if the Productions are in the following forms A a A BC S ε where A, B, and C are non-terminals and a is terminal. Algorithm to Convert into Chomsky Normal Form

49 Step 1 Step 2 Step 3 Step 4 Step 5 If the start symbol S occurs on some right side, create a new start symbol S and a new production S S. Remove Null productions. (Using the Null production removal algorithm discussed earlier) Remove unit productions. (Using the Unit production removal algorithm discussed earlier) Replace each production A B 1 B n where n > 2 with A B 1 C wherec B 2 B n. Repeat this step for all productions having two or more symbols in the right side. If the right side of any production is in the form A ab where a is a terminal and A, B are non-terminal, then the production is replaced bya XB and X a. Repeat this step for every production which is in the form A ab. Problem Convert the following CFG into CNF S ASA ab, A B S, B b Solution (1) Since S appears in R.H.S, we add a new state S 0 and S 0 S is added to the production set and it becomes S 0 S, S ASA ab, A B S, B b ε (2) Now we will remove the null productions B ε and A ε After removing B ε, the production set becomes S 0 S, S ASA ab a, A B S ε, B b After removing A ε, the production set becomes S 0 S, S ASA ab a AS SA S, A B S, B b (3) Now we will remove the unit productions. After removing S S, the production set becomes S 0 S, S ASA ab a AS SA, A B S, B b After removing S 0 S, the production set becomes S 0 ASA ab a AS SA, S ASA ab a AS SA A B S, B b

50 After removing A B, the production set becomes S 0 ASA ab a AS SA, S ASA ab a AS SA A S b B b After removing A S, the production set becomes S 0 ASA ab a AS SA, S ASA ab a AS SA A b ASA ab a AS SA, B b (4) Now we will find out more than two variables in the R.H.S Here, S 0 ASA, S ASA, A ASA violates two Non-terminals in R.H.S. Hence we will apply step 4 and step 5 to get the following final production set which is in CNF S 0 AX ab a AS SA S AX ab a AS SA A b AX ab a AS SA B b X SA (5) We have to change the productions S 0 ab, S ab, A ab And the final production set becomes S 0 AX YB a AS SA S AX YB a AS SA A b AX YB a AS SA B b X SA Y a Greibach Normal Form A CFG is in Greibach Normal Form if the Productions are in the following forms A b A bd 1 D n S ε where A, D 1,...,D n are non-terminals and b is a terminal. Algorithm to Convert a CFG into Greibach Normal Form

51 Step 1 Step 2 Step 3 Step 4 Step 5 If the start symbol S occurs on some right side, create a new start symbol S and a new production S S. Remove Null productions. (Using the Null production removal algorithm discussed earlier) Remove unit productions. (Using the Unit production removal algorithm discussed earlier) Remove all direct and indirect left-recursion. Do proper substitutions of productions to convert it into the proper form of GNF. Problem Convert the following CFG into CNF S XY X n p X mx m Y Xn o Solution Here, S does not appear on the right side of any production and there are no unit or null productions in the production rule set. So, we can skip Step 1 to Step 3. Step 4 Now after replacing X in S XY Xo p with mx m we obtain S mxy my mxo mo p. And after replacing X in Y X n o with the right side of X mx m we obtain Y mxn mn o.

52 Two new productions O o and P p are added to the production set and then we came to the final GNF as the following S mxy my mxc mc p X mx m Y mxd md o O o P p Example: CNF S XA BB B b SB X b A a NEW LABELS S = A 1 X = A 2 A = A 3 B = A 4 UPDATED CNF A 1 A 2 A 3 A 4 A 4 A 4 b A 1 A 4 A 2 b A 3 a GNF Consider the following example: Here's the grammar: S -> AA 0 A -> SS 1 first rename the variables: A1 -> A2 A2 0

53 A2 -> A1 A1 1 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING three of the four productions are just fine, only A2 -> A1 A1 is a problem. Apply algorithm 1: A2 -> A2 A2 A1 0 A1 So, now we have still have one problem production: A2 -> A2 A2 A1 Apply algorithm 2: A2 -> 1 0 A1 1 B 0 A1 B B -> A2 A1 A2 A1 B so now our grammar looks like: A1 -> A2 A2 0 A2 -> 1 0 A1 1 B 0 A1 B B -> A2 A1 A2 A1 B Now we must fix A1, so that is only starts with terminals: A1 -> 1 A2 0 A1 A2 1 B A2 0 A1 B A2 0 Then we must B in a similar fashion (replacing initial occurences of A2) B -> 1 A1 0 A1 A1 1 B A1 0 A1 B A1 1 A1 B 0 A1 A1 B 1 B A1 B 0 A1 B A1 B and now we have the following grammar: A1 -> 1 A2 0 A1 A2 1 B A2 0 A1 B A2 0 A2 -> 1 0 A1 1 B 0 A1 B B -> 1 A1 0 A1 A1 1 B A1 0 A1 B A1 1 A1 B 0 A1 A1 B 1 B A1 B 0 A1 B A1 B which is in GNF.

54 UNIT-III PUSHDOWN AUTOMATA

55 UNIT III PUSHDOWN AUTOMATA 9 Pushdown Automata- Definitions Moves Instantaneous descriptions Deterministic pushdown automata Equivalence of Pushdown automata and CFL pumping lemma for CFL problems based on pumping Lemma. Basic Structure of PDA A pushdown automaton is a way to implement a context-free grammar in a similar way we design DFA for a regular grammar. A DFA can remember a finite amount of information, but a PDA can remember an infinite amount of information. Basically a pushdown automaton is "Finite state machine" + "a stack" A pushdown automaton has three components an input tape, a control unit, and A stack with infinite size. The stack head scans the top symbol of the stack. A stack does two operations Push a new symbol is added at the top. Pop the top symbol is read and removed. A PDA may or may not read an input symbol, but it has to read the top of the stack in every transition.

56 A PDA can be formally described as a 7-tuple (Q,, S, δ, q 0, I, F) Q is the finite number of states is input alphabet S is stack symbols δ is the transition function Q ( {ε}) S Q S * q 0 is the initial state (q 0 Q) I is the initial stack top symbol (I S) F is a set of accepting states (F Q) The following diagram shows a transition in a PDA from a state q 1 to state q 2, labelled as a,b c This means at state q 1, if we encounter an input string a and top symbol of the stack is b, then we pop b, push c on top of the stack and move to stateq 2. Terminologies Related to PDA Instantaneous Description The instantaneous description (ID) of a PDA is represented by a triplet (q, w, s) where q is the state w is unconsumed input s is the stack contents Turnstile Notation The "turnstile" notation is used for connecting pairs of ID's that represent one or many moves of a PDA. The process of transition is denoted by the turnstile symbol " ". Consider a PDA (Q,, S, δ, q 0, I, F). A transition can be mathematically represented by the following turnstile notation

57 (p, aw, Tβ) (q, w, αb) This implies that while taking a transition from state p to state q, the input symbol a is consumed, and the top of the stack T is replaced by a new string α. Note If we want zero or more moves of a PDA, we have to use the symbol( * ) for it. There are two different ways to define PDA acceptability. Final State Acceptability In final state acceptability, a PDA accepts a string when, after reading the entire string, the PDA is in a final state. From the starting state, we can make moves that end up in a final state with any stack values. The stack values are irrelevant as long as we end up in a final state. For a PDA (Q,, S, δ, q 0, I, F), the language accepted by the set of final statesf is L(PDA) = {w (q 0, w, I) * (q, ε, x), q F} for any input stack string x. Empty Stack Acceptability Here a PDA accepts a string when, after reading the entire string, the PDA has emptied its stack. For a PDA (Q,, S, δ, q 0, I, F), the language accepted by the empty stack is L(PDA) = {w (q 0, w, I) * (q, ε, ε), q Q} Example Construct a PDA that accepts L= {0 n 1 n n 0} Solution This language accepts L = {ε, 01, 0011, ,...} Here, in this example, the number of a and b have to be same. Initially we put a special symbol $ into the empty stack.

58 Then at state q 2, if we encounter input 0 and top is Null, we push 0 into stack. This may iterate. And if we encounter input 1 and top is 0, we pop this 0. Example Then at state q 3, if we encounter input 1 and top is 0, we pop this 0. This may also iterate. And if we encounter input 1 and top is 0, we pop the top element. If the special symbol $ is encountered at top of the stack, it is popped out and it finally goes to the accepting state q 4.

59 Example Construct a PDA that accepts L= { ww R w = (a+b) * }

60 Solution Initially we put a special symbol $ into the empty stack. At state q 2, the w is being read. In state q 3, each 0 or 1 is popped when it matches the input. If any other input is given, the PDA will go to a dead state. When we reach that special symbol $, we go to the accepting state q 4. If a grammar G is context-free, we can build an equivalent nondeterministic PDA which accepts the language that is produced by the context-free grammarg. A parser can be built for the grammar G. Also, if P is a pushdown automaton, an equivalent context-free grammar G can be constructed where L(G) = L(P). versa. In the next two topics, we will discuss how to convert from PDA to CFG and vice Algorithm to find PDA corresponding to a given CFG Input A CFG, G= (V, T, P, S) Output Equivalent PDA, P= (Q,, S, δ, q 0, I, F) Step 1 Convert the productions of the CFG into GNF. Step 2 The PDA will have only one state {q}. Step 3 The start symbol of CFG will be the start symbol in the PDA. Step 4 All non-terminals of the CFG will be the stack symbols of the PDA and all the terminals of the CFG will be the input symbols of the PDA. Step 5 For each production in the form A ax where a is terminal and A, Xare combination of terminal and non-terminals, make a transition δ (q, a, A).

61 Problem Construct a PDA from the following CFG. G = ({S, X}, {a, b}, P, S) where the productions are S XS ε, A axb Ab ab Solution Let the equivalent PDA, P = ({q}, {a, b}, {a, b, X, S}, δ, q, S) where δ δ (q, ε, S) = {(q, XS), (q, ε )} δ(q, ε, X) = {(q, axb), (q, Xb), (q, ab)} δ(q, a, a) = {(q, ε )} δ(q, 1, 1) = {(q, ε )} Algorithm to find CFG corresponding to a given PDA Input A CFG, G= (V, T, P, S) Output Equivalent PDA, P = (Q,, S, δ, q 0, I, F) such that the non- terminals of the grammar G will be {X wx w,x Q} and the start state will be A q0,f. Step 1 For every w, x, y, z Q, m S and a, b, if δ (w, a, ε) contains (y, m) and (z, b, m) contains (x, ε), add the production rule X wx a X yz b in grammar G. Step 2 For every w, x, y, z Q, add the production rule X wx X wy X yx in grammar G. Step 3 For w Q, add the production rule X ww ε in grammar G. Parsing is used to derive a string using the production rules of a grammar. It is used to check the acceptability of a string. Compiler is used to check whether or not a string is syntactically correct. A parser takes the inputs and builds a parse tree.

62

63

64 NON DETERMINISTIC PUSH DOWN AUTOMATA

65 DETERMINISTIC PUSH DOWN AUTOMATA

66 A parser can be of two types Top-Down Parser Top-down parsing starts from the top with the start-symbol and derives a string using a parse tree. Bottom-Up Parser Bottom-up parsing starts from the bottom with the string and comes to the start symbol using a parse tree. Design of Top-Down Parser For top-down parsing, a PDA has the following four types of transitions Pop the non-terminal on the left hand side of the production at the top of the stack and push its right-hand side string. If the top symbol of the stack matches with the input symbol being read, pop it. Push the start symbol S into the stack. If the input string is fully read and the stack is empty, go to the final state F. Example Design a top-down parser for the expression "x+y*z" for the grammar G with the following production rules P: S S+X X, X X*Y Y, Y (S) id Solution If the PDA is (Q,, S, δ, q 0, I, F), then the top-down parsing is (x+y*z, I) (x +y*z, SI) (x+y*z, S+XI) (x+y*z, X+XI) (x+y*z, Y+X I) (x+y*z, x+xi) (+y*z, +XI) (y*z, XI) (y*z, X*YI) (y*z, y*yi) ( * z,*yi) (z, YI) (z, zi) (ε, I) Design of a Bottom-Up Parser For bottom-up parsing, a PDA has the following four types of transitions Push the current input symbol into the stack. Replace the right-hand side of a production at the top of the stack with its left-hand side. If the top of the stack element matches with the current input symbol, pop it. If the input string is fully read and only if the start symbol S remains in the stack, pop it and go to the final state F.

67 Example Design a top-down parser for the expression "x+y*z" for the grammar G with the following production rules P: S S+X X, X X*Y Y, Y (S) id Solution If the PDA is (Q,, S, δ, q 0, I, F), then the bottom-up parsing is (x+y*z, I) (+y*z, xi) (+y*z, YI) (+y*z, XI) (+y*z, SI) (y*z, +SI) ( * z, y+si) ( * z, Y+SI) ( * z, X+SI) (z, *X+SI) (ε, z*x+si) (ε, Y*X+SI) (ε, X+SI) (ε, SI) Pumping Lemma for CFLs In any sufficiently long string in a CFL, it is possible to find at most two short, nearby substrings that we can pump i times in tandem, for any integer i, and the resulting string will still be in that language. Pumping lemma for CFLs: Let L be a CFL. Then there exists a constant n such that if z L with z n, then we can write z = uvwxy, Subject to the following conditions: 1. vwx n. 2. vx 6=. 3. For all i 0, we have uv i wx i y L. If the string z is sufficiently long, then the parse tree produced by z has a variable symbol that is repeated on a path from the root to a leaf. Suppose A i = A j, such that the overall parse tree has yield z = uvwxy, the subtree for root A j has yield w, and the subtree for root A i has yield vwx. We can replace the subtree for root A i with the subtree for root A j, giving a tree with yield uwy (corresponding to the case i = 0), which also belongs to L. We can replace the subtree for root A j with the subtree for root A i, giving a tree with yield uv 2 wx 2 y (corresponding to the case i = 2), which also belongs to L. Etc. Examples

68 While CFLs can match two sub-strings for (in) equality of length, they cannot match three such sub-strings. Example 1: Consider L = {0 m 1 m 2 m m 1}. Pick n of the pumping lemma. Pick z = 0 n 1 n 2 n. Break z into uvwxy, with vwx n and vx 6=. Hence vwx cannot involve both 0s and 2s, since the last 0 and the first 2 are at least n + 1 po-sitions apart. There are two cases: vwx has no 2s. Then vx has only 0s and 1s. Then uwy, which would have to be in L, has n 2s, but fewer than n 0s or 1s. vwx has no 0s. Analogous. Hence L is not a CFL. CFLs cannot match two pairs of sub-strings of equal lengths if the pairs interleave. Example 2: Consider L = {0 i 1 j 2 i 3 j i, j 1}. Pick n of the pumping lemma. Pick z = 0 n 1 n 2 n 3 n. Break z into uvwxy, with vwx n and vx 6=. Then vwx contains one or two different sym-bols. In both cases, the string uwy cannot be in L. CFLs cannot match two sub-strings of arbi-trary length over an alphabet of at least two symbols. Example 3: Consider L = {ww w {0, 1} }. Pick n of the pumping lemma. Pick z = 0 n 1 n 0 n 1 n. In all cases, the string uwy cannot be in L.

69 UNIT IV TURING MACHINE

70 UNIT IV TURING MACHINES Definitions of Turing machines Models Computable languages and functions Techniques for Turing machine construction Multi head and Multi tape Turing Machines The Halting problem Partial Solvability Problems about Turing machine- Chomskian hierarchy of languages. A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type 0 grammars. It was invented in 1936 by Alan Turing. Definition A Turing Machine (TM) is a mathematical model which consists of an infinite length tape divided into cells on which input is given. It consists of a head which reads the input tape. A state register stores the state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left. If the TM reaches the final state, the input string is accepted, otherwise rejected. A TM can be formally described as a 7-tuple (Q, X,, δ, q 0, B, F) where Q is a finite set of states X is the tape alphabet is the input alphabet δ is a transition function; δ : Q X Q X {Left_shift, Right_shift}. q 0 is the initial state B is the blank symbol F is the set of final states Comparison with the previous automation The following table shows a comparison of how a Turing machine differs from Finite Automaton and Pushdown Automaton.

71 Machine Stack Data Structure Deterministic? Finite Automaton N.A Yes Pushdown Automaton Last In First Out(LIFO) No Turing Machine Infinite tape Yes Example of Turing machine Turing machine M = (Q, X,, δ, q 0, B, F) with Q = {q 0, q 1, q 2, q f } X = {a, b} = {1} q 0 = {q 0 } B = blank symbol F = {q f } δ is given by Tape alphabet Present State Present State Present State symbol q 0 q 1 q 2 a 1Rq 1 1Lq 0 1Lq f b 1Lq 2 1Rq 1 1Rq f Here the transition 1Rq 1 implies that the write symbol is 1, the tape moves right, and the next state is q 1. Similarly, the transition 1Lq 2 implies that the write symbol is 1, the tape moves left, and the next state is q 2. Time and Space Complexity of a Turing Machine

72 For a Turing machine, the time complexity refers to the measure of the number of times the tape moves when the machine is initialized for some input symbols and the space complexity is the number of cells of the tape written. Time complexity all reasonable functions T(n) = O(n log n) TM's space complexity S(n) = O(n) A TM accepts a language if it enters into a final state for any input string w. A language is recursively enumerable (generated by Type-0 grammar) if it is accepted by a Turing machine. A TM decides a language if it accepts it and enters into a rejecting state for any input not in the language. A language is recursive if it is decided by a Turing machine. There may be some cases where a TM does not stop. Such TM accepts the language, but it does not decide it. Designing a Turing Machine The basic guidelines of designing a Turing machine have been explained below with the help of a couple of examples. Example 1 Design a TM to recognize all strings consisting of an odd number of α s. Solution The Turing machine M can be constructed by the following moves Let q 1 be the initial state. If M is in q 1 ; on scanning α, it enters the state q 2 and writes B (blank). If M is in q 2 ; on scanning α, it enters the state q 1 and writes B (blank). From the above moves, we can see that M enters the state q 1 if it scans an even number of α s, and it enters the state q 2 if it scans an odd number of α s. Hence q 2 is the only accepting state. Hence, M = {{q 1, q 2 }, {1}, {1, B}, δ, q 1, B, {q 2 }} where δ is given by

73 Tape alphabet symbol Present State q 1 Present State q 2 a BRq 2 BRq 1 Example 2 Design a Turing Machine that reads a string representing a binary number and erases all leading 0 s in the string. However, if the string comprises of only 0 s, it keeps one 0. Solution Let us assume that the input string is terminated by a blank symbol, B, at each end of the string. The Turing Machine, M, can be constructed by the following moves Let q 0 be the initial state. If M is in q 0, on reading 0, it moves right, enters the state q 1 and erases 0. On reading 1, it enters the state q 2 and moves right. If M is in q 1, on reading 0, it moves right and erases 0, i.e., it replaces 0 s by B s. On reaching the leftmost 1, it enters q 2 and moves right. If it reaches B, i.e., the string comprises of only 0 s, it moves left and enters the state q 3. If M is in q 2, on reading either 0 or 1, it moves right. On reaching B, it moves left and enters the state q 4. This validates that the string comprises only of 0 s and 1 s. If M is in q 3, it replaces B by 0, moves left and reaches the final stateq f. If M is in q 4, on reading either 0 or 1, it moves left. On reaching the beginning of the string, i.e., when it reads B, it reaches the final state q f. Hence, M = {{q 0, q 1, q 2, q 3, q 4, q f }, {0,1, B}, {1, B}, δ, q 0, B, {q f }} where δ is given by Tape alphabet symbol Present State q 0 Present State q 1 Present State q 2 Present State q 3 Present State q 4 0 BRq 1 BRq 1 ORq 2 - OLq 4

74 1 1Rq 2 1Rq 2 1Rq 2-1Lq 4 B BRq 1 BLq 3 BLq 4 OLq f BRq f

75 Turing machine computable functions A Turing machine computes a function f : Σ Σ if, for any input word w, it always stops in a configuration where f(w) is on the tape. The functions that are computable by an effective procedure are those that are computable by a Turing machine

76

77

78

79

80

81

82

83

84

85

86 Techniques for Turing Machine Construction Designing a Turing machine to solve a problem is an interesting task. It is somewhat similar to programming. Given a problem, different Turing machines can be constructed to solve it. But we would like to have a Turing machine which does it in a simple and efficient manner. Like we learn some techniques of programming to deal with alternatives, loops etc, it is helpful to understand some techniques in Turing machine construction, which will help in designing simple and efficient Turing machines. It should be noted that we are using the word efficient in an intuitive manner here. 1. Considering the state as a tuple. In an earlier example we considered a Turing machine which makes a copy of a given string over Σ = {a, b}. After reading a a, the machine remembers it by going to qa and after reading a b, it goes to qb. In general we can represent the state as [q, x] where x Σ denoting that it has read a x. 2. Considering the tape symbol as a tuple. Sometimes we may want to mark some symbols without destroying them or do some computation without destroying the input. In such cases it is advisable to have multiple tracks on the tape. This is equivalent to considering the tape symbol as a tuple.

87 There is only one tape head. In the above figure there are three tracks. The head is pointing to a cell which contains A on the first track, B on the second track and C on the third track. The tape symbol is taken a 3-tuple [A, B, C]. Some computation can be done in one track by manipulating the respective component of the tape symbol. This is very useful in checking off symbols. 3. Checking off symbols. We use one track of the tape to mark that some symbols have been read without changing them. Example Consider a Turing machine for accepting w#w#w, w {a, b} A tape having two tracks is considered. The first track contains the input. When the TM reads the first a in state q0, it stores it in its memory (by taking the state as a pair), checks off a by printing a in the second track below a, moves right and after the # symbol checks whether the symbol is a a. If so marks it by putting a in the second track, moves right and again checks the first symbol after # is a a and if so it marks also. It then moves left and repeats the process with each unmarked leftmost symbols in each block. When all the symbols in the first block match with the second and third blocks, the machine halts accepting the string. The mappings can be defined as follows: δ(q0, [a, 6b]) = ([q, a], [a, ], R) δ(q0, [b, 6b]) = ([q, b], [b, ], R) The machine reads the leftmost symbol marks it and remembers whether it is a a or b by storing it in the state δ([q, a], [a, 6b]) = ([q, a], [a, 6b], R) δ([q, a], [b, 6b]) = ([q, a], [b, 6b], R)

88 δ([q, b], [a, 6b]) = ([q, b], [a, 6b], R) δ([q, b], [b, 6b]) = ([q, b], [b, 6b], R) The head passes through symbols in the first block to the right δ([q, a], [#, 6b]) = ([p, a], [#, 6b], R) δ([q, b], [#, 6b]) = ([p, b], [#, b], R) When the head encounters a # in the first track, the first component of the state is changed to p. δ([p, a], [a, ]) = ([p, a], [a, ], R) δ([p, a], [b, ]) = ([p, a], [b, ], R) δ([p, b], [a, ]) = ([p, b], [a, ], R) δ([p, b], [b, ]) = ([p, b], [b, ], R) δ([p, a], [a, 6b]) = ([r, a], [a, ], R) δ([p, b], [b, 6b]) = ([r, b], [b, ], R) When it encounters a first unchecked symbol it marks it by putting a in the second track and changes the first component of the state to r. δ([r, a], [a, 6b]) = ([r, a], [a, 6b], R) δ([r, b], [a, 6b]) = ([r, b], [a, 6b], R) δ([r, a], [b, 6b]) = ([r, a], [b, 6b], R) δ([r, b], [b, 6b]) = ([r, b], [b, 6b], R) The head moves through the second block without changing symbols, when the first component of the state is r δ([r, a], [#, 6b]) = ([s, a], [#, 6b], R) δ([r, b], [#, 6b]) = ([s, b], [#, 6b], R) When it encounters a # in the first track it moves right into the third block changing the first component of the state to s δ([s, a], [a, ]) = ([s, a], [a, ], R) δ([s, a], [b, ]) = ([s, a], [b, ], R) δ([s, b], [a, ]) = ([s, b], [a, ], R) δ([s, b], [b, ]) = ([s, b], [b, ], R) It moves right looking for the unchecked symbol δ([s, b], [b, 6b]) = (t, [b, ],L) δ([s, a], [a, 6b]) = (t, [a, ],L) When it encounters an unchecked symbol in the third

89 it marks it by putting a in the second track and starts moving left. δ(t, [a, ]) = (t, [a, ],L) δ(t, [b, ]) = (t, [b, ],L) δ(t, [#, ]) = (t0, [#, ],L) It moves into the second block in state t0 δ(t0, [a, 6b]) = (t0, [a, 6b],L) δ(t0, [b, 6b]) = (t0, [b, 6b],L) δ(t0, [a, ]) = (t0, [a, ],L) δ(t0, [b, ]) = (t0, [b, ],L) It moves left in the second block. δ(t0, [#, 6b]) = (t00, [#, b],l) It moves left into the first block in state t00 δ(t00, [a, 6b]) = (t00, [a, 6b],L) δ(t00, [b, 6b]) = (t00, [b, 6b],L) It moves left in the first block through unchecked symbols. When it encounters a checked symbol it moves right in state q0 and the whole process repeats δ(t00, [a, ]) = (q0, [a, ], R) δ(t00, [b, ]) = (q0, [b, ], R) This way the machine checks for same symbols in the first, second and third blocks. Finishing When the machine encounters a # in the first track in state q0, it means it has checked all symbols in the first block. Now it has to check that there Introduction to Fare ormal Languages, no Automata more symbols in the second and third block. δ(q0, [#, 6b]) = (q1, [#, 6b], R) δ(q1, [a, ]) = (q1, [a, ], R) δ(q1, [b, ]) = (q1, [b, ], R) If it encounters an unchecked symbol, it halts without accepting δ(q1, [a, 6b]) = (qn, [a, 6b], R) δ(q1, [b, 6b]) = (qn, [b, 6b], R) If it finds all symbols are checked in the second block, it moves to the third block in state q2 δ(q1, [#, 6b]) = (q2, [#, 6b], R) In the third block it checks whether all symbols have already been checked. If so, it halts in accepting state qy.

90 Otherwise halts in nonaccepting state qn δ(q2, [a, ]) = (q2, [a, ], R) δ(q2, [b, ]) = (q2, [b, ], R) δ(q2, [a, 6b]) = (qn, [a, 6b], R) δ(q2, [b, 6b]) = (qn, [b, 6b], R) δ(q2, [6b, 6b]) = (qy, [6b, 6b], R) If the input has more symbols in the first block (than second block) it moves in the second block in state [p, a] or [p, b] and encounters [#, 6b]. Then it halts rejecting the input δ([p, a], [#, 6b]) = (qn, [#, 6b], R) δ([p, b], [#, 6b]) = (qn, [#, 6b], R) If the input has equal symbols in the first and second block but less symbols in the third block, the machine encounters [6b, 6b] an state [s, b] or [s, a] and halts without accepting δ([s, a], [6b, 6b]) = (qn, [6b, 6b], R) δ([s, b], [6b, 6b]) = (qn, [6b, 6b], R) Thus we find that having two tracks and using the second track to check off symbols is a useful technique. When we consider a single tape multitrack TM, we really take the tape symbol as a tuple. This need not be considered as a variation of Turing machine. 4. Shifting over. Sometimes we may have to shift symbols on the tape to the right or left to allow for some symbols to be written. Suppose the contents of the tape are a1... ai 1Aai+1... an at some instant. A has to be replaced by abcd say. Then ai+1... an have to be shifted three cells to the right and then in the space created abcd can be printed. We can use the state as a tuple to store some information and shift symbols. Suppose the head is reading ai+1 in state q and the shifting process has to start. Then the TM reads ai+1 and goes to a state [q,,, ai+1] and prints X over ai. The ID

91

92 In q0 it moves left till it finds AXXX and replaces it by abcd. A similar method can be used for shifting symbols to the left. Thus storing some information in some components of the state and cyclically moving the components helps in the technique of shifting off symbols. 5. Subroutines. Just as a computer program has a main procedure and subroutines, the TM can also be programmed to have a main TM and TMs which serve as subroutines. Suppose we have to make n copies of a word w. Input is #w# and the output is #w# w ww{z... w} n times. In this case we can write the mappings for a TM Msub which when started on #w#x ends up with #w#xw. The main TM will call this Msub x times. Multitape Turing Machine Multi-tape Turing Machines have multiple tapes where each tape is accessed with a separate head. Each head can move independently of the other heads. Initially the input is on tape 1 and others are blank. At first, the first tape is occupied by the input and the other tapes are kept blank. Next, the machine reads consecutive symbols under its heads and the TM prints a symbol on each tape and moves its heads.

93 A Multi-tape Turing machine can be formally described as a 6-tuple (Q, X, B, δ, q 0, F) where Q is a finite set of states X is the tape alphabet B is the blank symbol δ is a relation on states and symbols where δ: Q X k Q (X {Left_shift, Right_shift, No_shift }) k where there is k number of tapes q 0 is the initial state F is the set of final states Note Every Multi-tape Turing machine has an equivalent single-tape Turing machine. Multi Head Turing Machine

94

95

96 Halting Problem Halting Problem is Undecidable

97 Example Problems on Turing Machine Example 1

98

99

100 Chomsikan Hierarchy of Languages According to Noam Chomosky, there are four types of grammars Type 0, Type 1, Type 2, and Type 3. The following table shows how they differ from each other Grammar Type Grammar Accepted Language Accepted Automaton Type 0 Unrestricted grammar Recursively enumerable language Turing Machine Type 1 Context-sensitive grammar Contextsensitive language Linearbounded automaton Type 2 Context-free grammar Context-free language Pushdown automaton Type 3 Regular grammar Regular language Finite state automaton Take a look at the following illustration. It shows the scope of each type of grammar

101 Type - 3 Grammar Type-3 grammars generate regular languages. Type-3 grammars must have a single nonterminal on the left-hand side and a right-hand side consisting of a single terminal or single terminal followed by a single non-terminal. The productions must be in the form X a or X ay where X, Y N (Non terminal) and a T (Terminal) The rule S ε is allowed if S does not appear on the right side of any rule. Example X ε X a X ay Type - 2 Grammar Type-2 grammars generate context-free languages. The productions must be in the form A γ where A N (Non terminal) and γ (T N) * (String of terminals and non-terminals).

102 These languages generated by these grammars are be recognized by a non-deterministic pushdown automaton. Example S X a, X a, X Ax, X abc, X ε Type - 1 Grammar Type-1 grammars generate context-sensitive languages. The productions must be in the form α A β α γ β where A N (Non-terminal) and α, β, γ (T N) * (Strings of terminals and non-terminals) The strings α and β may be empty, but γ must be non-empty. The rule S ε is allowed if S does not appear on the right side of any rule. The languages generated by these grammars are recognized by a linear bounded automaton. Example AB AbBc A bca B b Type - 0 Grammar Type-0 grammars generate recursively enumerable languages. The productions have no restrictions. They are any phase structure grammar including all formal grammars. They generate the languages that are recognized by a Turing machine. The productions can be in the form of α β where α is a string of terminals and nonterminals with at least one non-terminal and α cannot be null. β is a string of terminals and non-terminals. Example S ACaB Bc acb CB DB ad Db

103 UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS

104 UNIT V UNSOLVABLE PROBLEMS AND COMPUTABLE FUNCTIONS Unsolvable Problems and Computable Functions Primitive recursive functions Recursive and recursively enumerable languages Universal Turing machine. MEASURING AND CLASSIFYING COMPLEXITY: Tractable and Intractable problems- Tractable and possibly intractable problems P and NP completeness Polynomial time reductions Decidability A language is called Decidable or Recursive if there is a Turing machine which accepts and halts on every input string w. Every decidable language is Turing-Acceptable. A decision problem P is decidable if the language L of all yes instances to P is decidable. For a decidable language, for each input string, the TM halts either at the accept or the reject state as depicted in the following diagram

105 Example 1 Find out whether the following problem is decidable or not Is a number m prime? Solution Prime numbers = {2, 3, 5, 7, 11, 13,..} Divide the number m by all the numbers between 2 and m starting from 2. If any of these numbers produce a remainder zero, then it goes to the Rejected state, otherwise it goes to the Accepted state. So, here the answer could be made by Yes or No. Hence, it is a decidable problem. Example 2 Given a regular language L and string w, how can we check if w L? Solution Take the DFA that accepts L and check if w is accepted

106 Some more decidable problems are Note Does DFA accept the empty language? Is L 1 L 2 = for regular sets? If a language L is decidable, then its complement L' is also decidable. If a language is decidable, then there is an enumerator for it. Undecidable Language For an undecidable language, there is no Turing Machine which accepts the language and makes a decision for every input string w (TM can make decision for some input string though). A decision problem P is called undecidable if the language L of all yes instances to P is not decidable. Undecidable languages are not recursive languages, but sometimes, they may be recursively enumerable languages.

107 Example The halting problem of Turing machine The mortality problem The mortal matrix problem The Post correspondence problem, etc. Recursively Enumerable Languages Recursive Languages

108 Relationship between Recursively Enumerable and Recursive Languages

109 Decision Problems Decidable or Solvable problems

110 Self Accepting NSA is not recursively Enumerable

111 SA is recursively enumerable SA is not recursive

112

113 Reduction

114 Properties of Reduction

115 Using reduction to prove decidability

116 Universal Turing Machine

117 Encoding Function Example of Encode TM

118 Universal Turing Machine DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING How UTM works

119 Rice s Theorem Theorem L= {<M> L (M) P} is undecidable when p, a non-trivial property of the Turing machine, is undecidable. If the following two properties hold, it is proved as undecidable Property 1 If M1 and M2 recognize the same language, then either <M1><M2> L or <M1> <M2> L Property 2 For some M1 and M2 such that <M1> L and <M2> L Let there are two Turing machines X 1 and X 2. Let us assume <X 1 > L such that L(X 1 ) = φ and <X 2 > L. For an input w in a particular instant, perform the following steps If X accepts w, then simulate X 2 on x. Run Z on input <W>. If Z accepts <W>, Reject it; and if Z rejects <W>, accept it. If X accepts w, then L(W) = L(X 2 ) and <W> P If M does not accept w, then L(W) = L(X 1 ) = φ and <W> P Here the contradiction arises. Hence, it is undecidable. POST CORRESPONDENCE PROBLEM (PCP) The Post Correspondence Problem (PCP), introduced by Emil Post in 1946, is an undecidable decision problem. The PCP problem over an alphabet is stated as follows Given the following two lists, M and N of non-empty strings over M= (x 1, x 2, x 3,, x n ) N= (y 1, y 2, y 3,, y n ) We can say that there is a Post Correspondence Solution, if for some i 1, i 2, i k, where 1 i j n, the condition x i1.x ik = y i1...y ik satisfies.

120 Example Find whether the lists M = (abb, aa, aaa) and N = (bba, aaa, aa) have a Post Correspondence Solution? Solution x 1 x 2 x 3 M Abb aa aaa N Bba aaa aa Here, x 2 x 1 x 3 = aaabbaaa and y 2 y 1 y 3 = aaabbaaa We can see that x 2 x 1 x 3 = y 2 y 1 y 3 Hence, the solution is i=2, j =1, and k=3. Example 2 Find whether the lists M = (ab, bab, bbaaa) and N = (a, ba, bab) have a Post Correspondence Solution? Solution x 1 x 2 x 3 M ab bab bbaaa N a ba bab In this case, there is no solution because

121 x 2 x 1 x 3 y 2 y 1 y 3 (Lengths are not same) Hence, it can be said that this Post Correspondence Problem is undecidable.

122

123 P, NP-Complete, NP, and NP-Hard DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING NP problems have their own significance in programming, but the discussion becomes quite hot when we deal with differences between NP, P, NP-Complete and NP-hard. P and NP- Many of us know the difference between them. P- Polynomial time solving. Problems which can be solved in polynomial time, which take time like O(n), O(n2), O(n3). Eg: finding maximum element in an array or to check whether a string is palindrome or not. so there are many problems which can be solved in polynomial time. NP- Non deterministic Polynomial time solving. Problem which can't be solved in polynomial time like TSP( travelling salesman problem) or An easy example of this is subset sum: given a set of numbers, does there exist a subset whose sum is zero?. but NP problems are checkable in polynomial time means that given a solution of a problem, we can check that whether the solution is correct or not in polynomial time. So till now you have got what is NP and what is P. Now we will discuss about NP-Complete and NP-hard. but first we need to know what is reducibility. Take two problems A and B both are NP problems. Reducibility- If we can convert one instance of a problem A into problem B (NP problem) then it means that A is reducible to B. NP-hard-- Now suppose we found that A is reducible to B, then it means that B is at least as hard as A. NP-Complete -- The group of problems which are both in NP and NP-hard are known as NP- Complete problem. Now suppose we have a NP-Complete problem R and it is reducible to Q then Q is at least as hard as R and since R is an NP-hard problem. therefore Q will also be at least NP-hard, it may be NP-complete also.

124 Polynomial Time Reduction

Theory of Computation Turing Machine and Pushdown Automata

Theory of Computation Turing Machine and Pushdown Automata Theory of Computation Turing Machine and Pushdown Automata 1. What is a Turing Machine? A Turing Machine is an accepting device which accepts the languages (recursively enumerable set) generated by type

More information

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM).

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM). Automata The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled computing device which follows a predetermined

More information

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET Regular Languages and FA A language is a set of strings over a finite alphabet Σ. All languages are finite or countably infinite. The set of all languages

More information

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013 Q.2 a. Prove by mathematical induction n 4 4n 2 is divisible by 3 for n 0. Basic step: For n = 0, n 3 n = 0 which is divisible by 3. Induction hypothesis: Let p(n) = n 3 n is divisible by 3. Induction

More information

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES Contents i SYLLABUS UNIT - I CHAPTER - 1 : AUT UTOMA OMATA Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 2 : FINITE AUT UTOMA OMATA An Informal Picture of Finite Automata,

More information

Theory of Computation - Module 4

Theory of Computation - Module 4 Theory of Computation - Module 4 Syllabus Turing Machines Formal definition Language acceptability by TM TM as acceptors, Transducers - designing of TM- Two way infinite TM- Multi tape TM - Universal Turing

More information

Section 1 (closed-book) Total points 30

Section 1 (closed-book) Total points 30 CS 454 Theory of Computation Fall 2011 Section 1 (closed-book) Total points 30 1. Which of the following are true? (a) a PDA can always be converted to an equivalent PDA that at each step pops or pushes

More information

Foundations of Informatics: a Bridging Course

Foundations of Informatics: a Bridging Course Foundations of Informatics: a Bridging Course Week 3: Formal Languages and Semantics Thomas Noll Lehrstuhl für Informatik 2 RWTH Aachen University noll@cs.rwth-aachen.de http://www.b-it-center.de/wob/en/view/class211_id948.html

More information

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014 Q.2 a. Show by using Mathematical Induction that n i= 1 i 2 n = ( n + 1) ( 2 n + 1) 6 b. Define language. Let = {0; 1} denote an alphabet. Enumerate five elements of the following languages: (i) Even binary

More information

Introduction to Theory of Computing

Introduction to Theory of Computing CSCI 2670, Fall 2012 Introduction to Theory of Computing Department of Computer Science University of Georgia Athens, GA 30602 Instructor: Liming Cai www.cs.uga.edu/ cai 0 Lecture Note 3 Context-Free Languages

More information

Introduction to Formal Languages, Automata and Computability p.1/42

Introduction to Formal Languages, Automata and Computability p.1/42 Introduction to Formal Languages, Automata and Computability Pushdown Automata K. Krithivasan and R. Rama Introduction to Formal Languages, Automata and Computability p.1/42 Introduction We have considered

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be

More information

Theory of Computation - Module 3

Theory of Computation - Module 3 Theory of Computation - Module 3 Syllabus Context Free Grammar Simplification of CFG- Normal forms-chomsky Normal form and Greibach Normal formpumping lemma for Context free languages- Applications of

More information

UNIT-VIII COMPUTABILITY THEORY

UNIT-VIII COMPUTABILITY THEORY CONTEXT SENSITIVE LANGUAGE UNIT-VIII COMPUTABILITY THEORY A Context Sensitive Grammar is a 4-tuple, G = (N, Σ P, S) where: N Set of non terminal symbols Σ Set of terminal symbols S Start symbol of the

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING DUNDIGAL 500 043, HYDERABAD COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : FORMAL LANGUAGES AND AUTOMATA THEORY Course Code : A40509 Class :

More information

Properties of Context-free Languages. Reading: Chapter 7

Properties of Context-free Languages. Reading: Chapter 7 Properties of Context-free Languages Reading: Chapter 7 1 Topics 1) Simplifying CFGs, Normal forms 2) Pumping lemma for CFLs 3) Closure and decision properties of CFLs 2 How to simplify CFGs? 3 Three ways

More information

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-500 014 Subject: FORMAL LANGUAGES AND AUTOMATA THEORY Class : CSE II PART A (SHORT ANSWER QUESTIONS) UNIT- I 1 Explain transition diagram, transition

More information

Computational Models - Lecture 4

Computational Models - Lecture 4 Computational Models - Lecture 4 Regular languages: The Myhill-Nerode Theorem Context-free Grammars Chomsky Normal Form Pumping Lemma for context free languages Non context-free languages: Examples Push

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation CFL Hierarchy CFL Decision Problems Your Questions? Previous class days' material Reading Assignments HW 12 or 13 problems Anything else I have included some slides online

More information

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm Testing Emptiness of a CFL As for regular languages, we really take a representation of some language and ask whether it represents φ Can use either CFG or PDA Our choice, since there are algorithms to

More information

Computability and Complexity

Computability and Complexity Computability and Complexity Push-Down Automata CAS 705 Ryszard Janicki Department of Computing and Software McMaster University Hamilton, Ontario, Canada janicki@mcmaster.ca Ryszard Janicki Computability

More information

Automata and Computability. Solutions to Exercises

Automata and Computability. Solutions to Exercises Automata and Computability Solutions to Exercises Fall 28 Alexis Maciel Department of Computer Science Clarkson University Copyright c 28 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 1 Table of Contents: Week 1: Preliminaries (set algebra, relations, functions) (read Chapters

More information

Question Bank UNIT I

Question Bank UNIT I Siddhivinayak Technical Campus School of Engineering & Research Technology Department of computer science and Engineering Session 2016-2017 Subject Name- Theory of Computation Subject Code-4KS05 Sr No.

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 14 Ana Bove May 14th 2018 Recap: Context-free Grammars Simplification of grammars: Elimination of ǫ-productions; Elimination of

More information

Properties of Context-Free Languages

Properties of Context-Free Languages Properties of Context-Free Languages Seungjin Choi Department of Computer Science and Engineering Pohang University of Science and Technology 77 Cheongam-ro, Nam-gu, Pohang 37673, Korea seungjin@postech.ac.kr

More information

Automata and Computability. Solutions to Exercises

Automata and Computability. Solutions to Exercises Automata and Computability Solutions to Exercises Spring 27 Alexis Maciel Department of Computer Science Clarkson University Copyright c 27 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

More information

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar TAFL 1 (ECS-403) Unit- III 3.1 Definition of CFG (Context Free Grammar) and problems 3.2 Derivation 3.3 Ambiguity in Grammar 3.3.1 Inherent Ambiguity 3.3.2 Ambiguous to Unambiguous CFG 3.4 Simplification

More information

Theory Bridge Exam Example Questions

Theory Bridge Exam Example Questions Theory Bridge Exam Example Questions Annotated version with some (sometimes rather sketchy) answers and notes. This is a collection of sample theory bridge exam questions. This is just to get some idea

More information

Final exam study sheet for CS3719 Turing machines and decidability.

Final exam study sheet for CS3719 Turing machines and decidability. Final exam study sheet for CS3719 Turing machines and decidability. A Turing machine is a finite automaton with an infinite memory (tape). Formally, a Turing machine is a 6-tuple M = (Q, Σ, Γ, δ, q 0,

More information

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs Harry Lewis October 8, 2013 Reading: Sipser, pp. 119-128. Pushdown Automata (review) Pushdown Automata = Finite automaton

More information

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a.

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a. VTU 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 )( Dec-2014) 2. Obtain a DFA to accept strings of a s and b s having even

More information

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3}, Code No: 07A50501 R07 Set No. 2 III B.Tech I Semester Examinations,MAY 2011 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 80 Answer any FIVE Questions All

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION FORMAL LANGUAGES, AUTOMATA AND COMPUTATION DECIDABILITY ( LECTURE 15) SLIDES FOR 15-453 SPRING 2011 1 / 34 TURING MACHINES-SYNOPSIS The most general model of computation Computations of a TM are described

More information

SCHEME FOR INTERNAL ASSESSMENT TEST 3

SCHEME FOR INTERNAL ASSESSMENT TEST 3 SCHEME FOR INTERNAL ASSESSMENT TEST 3 Max Marks: 40 Subject& Code: Automata Theory & Computability (15CS54) Sem: V ISE (A & B) Note: Answer any FIVE full questions, choosing one full question from each

More information

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen

Pushdown Automata. Notes on Automata and Theory of Computation. Chia-Ping Chen Pushdown Automata Notes on Automata and Theory of Computation Chia-Ping Chen Department of Computer Science and Engineering National Sun Yat-Sen University Kaohsiung, Taiwan ROC Pushdown Automata p. 1

More information

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP CS 301 - Lecture 29 P, NP, and NP-Completeness Fall 2008 Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata Equivalence of

More information

This lecture covers Chapter 7 of HMU: Properties of CFLs

This lecture covers Chapter 7 of HMU: Properties of CFLs This lecture covers Chapter 7 of HMU: Properties of CFLs Chomsky Normal Form Pumping Lemma for CFs Closure Properties of CFLs Decision Properties of CFLs Additional Reading: Chapter 7 of HMU. Chomsky Normal

More information

CISC4090: Theory of Computation

CISC4090: Theory of Computation CISC4090: Theory of Computation Chapter 2 Context-Free Languages Courtesy of Prof. Arthur G. Werschulz Fordham University Department of Computer and Information Sciences Spring, 2014 Overview In Chapter

More information

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY No part of this publication may be reproduced or distributed in any form or any means, electronic, mechanical, photocopying, or otherwise without the prior permission of the author. GATE SOLVED PAPER Computer

More information

Undecidable Problems and Reducibility

Undecidable Problems and Reducibility University of Georgia Fall 2014 Reducibility We show a problem decidable/undecidable by reducing it to another problem. One type of reduction: mapping reduction. Definition Let A, B be languages over Σ.

More information

Automata Theory (2A) Young Won Lim 5/31/18

Automata Theory (2A) Young Won Lim 5/31/18 Automata Theory (2A) Copyright (c) 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later

More information

DD2371 Automata Theory

DD2371 Automata Theory KTH CSC VT 2008 DD2371 Automata Theory Dilian Gurov Lecture Outline 1. The lecturer 2. Introduction to automata theory 3. Course syllabus 4. Course objectives 5. Course organization 6. First definitions

More information

Theory of Computation (Classroom Practice Booklet Solutions)

Theory of Computation (Classroom Practice Booklet Solutions) Theory of Computation (Classroom Practice Booklet Solutions) 1. Finite Automata & Regular Sets 01. Ans: (a) & (c) Sol: (a) The reversal of a regular set is regular as the reversal of a regular expression

More information

CPSC 421: Tutorial #1

CPSC 421: Tutorial #1 CPSC 421: Tutorial #1 October 14, 2016 Set Theory. 1. Let A be an arbitrary set, and let B = {x A : x / x}. That is, B contains all sets in A that do not contain themselves: For all y, ( ) y B if and only

More information

UNIT-VI PUSHDOWN AUTOMATA

UNIT-VI PUSHDOWN AUTOMATA Syllabus R09 Regulation UNIT-VI PUSHDOWN AUTOMATA The context free languages have a type of automaton that defined them. This automaton, called a pushdown automaton, is an extension of the nondeterministic

More information

Theory of Computation (IX) Yijia Chen Fudan University

Theory of Computation (IX) Yijia Chen Fudan University Theory of Computation (IX) Yijia Chen Fudan University Review The Definition of Algorithm Polynomials and their roots A polynomial is a sum of terms, where each term is a product of certain variables and

More information

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer. Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer. Language Generator: Context free grammars are language generators,

More information

Accept or reject. Stack

Accept or reject. Stack Pushdown Automata CS351 Just as a DFA was equivalent to a regular expression, we have a similar analogy for the context-free grammar. A pushdown automata (PDA) is equivalent in power to contextfree grammars.

More information

Einführung in die Computerlinguistik

Einführung in die Computerlinguistik Einführung in die Computerlinguistik Context-Free Grammars (CFG) Laura Kallmeyer Heinrich-Heine-Universität Düsseldorf Summer 2016 1 / 22 CFG (1) Example: Grammar G telescope : Productions: S NP VP NP

More information

DM17. Beregnelighed. Jacob Aae Mikkelsen

DM17. Beregnelighed. Jacob Aae Mikkelsen DM17 Beregnelighed Jacob Aae Mikkelsen January 12, 2007 CONTENTS Contents 1 Introduction 2 1.1 Operations with languages...................... 2 2 Finite Automata 3 2.1 Regular expressions/languages....................

More information

CPS 220 Theory of Computation

CPS 220 Theory of Computation CPS 22 Theory of Computation Review - Regular Languages RL - a simple class of languages that can be represented in two ways: 1 Machine description: Finite Automata are machines with a finite number of

More information

CpSc 421 Final Exam December 15, 2006

CpSc 421 Final Exam December 15, 2006 CpSc 421 Final Exam December 15, 2006 Do problem zero and six of problems 1 through 9. If you write down solutions for more that six problems, clearly indicate those that you want graded. Note that problems

More information

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY 15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form:

More information

Functions on languages:

Functions on languages: MA/CSSE 474 Final Exam Notation and Formulas page Name (turn this in with your exam) Unless specified otherwise, r,s,t,u,v,w,x,y,z are strings over alphabet Σ; while a, b, c, d are individual alphabet

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 15 Ana Bove May 17th 2018 Recap: Context-free Languages Chomsky hierarchy: Regular languages are also context-free; Pumping lemma

More information

CS20a: summary (Oct 24, 2002)

CS20a: summary (Oct 24, 2002) CS20a: summary (Oct 24, 2002) Context-free languages Grammars G = (V, T, P, S) Pushdown automata N-PDA = CFG D-PDA < CFG Today What languages are context-free? Pumping lemma (similar to pumping lemma for

More information

Introduction to Turing Machines. Reading: Chapters 8 & 9

Introduction to Turing Machines. Reading: Chapters 8 & 9 Introduction to Turing Machines Reading: Chapters 8 & 9 1 Turing Machines (TM) Generalize the class of CFLs: Recursively Enumerable Languages Recursive Languages Context-Free Languages Regular Languages

More information

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata. Code No: R09220504 R09 Set No. 2 II B.Tech II Semester Examinations,December-January, 2011-2012 FORMAL LANGUAGES AND AUTOMATA THEORY Computer Science And Engineering Time: 3 hours Max Marks: 75 Answer

More information

V Honors Theory of Computation

V Honors Theory of Computation V22.0453-001 Honors Theory of Computation Problem Set 3 Solutions Problem 1 Solution: The class of languages recognized by these machines is the exactly the class of regular languages, thus this TM variant

More information

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu Part 4 out of 5 ETH Zürich (D-ITET) October, 12 2017 Last week, we showed the equivalence of DFA, NFA and REX

More information

Pushdown Automata (2015/11/23)

Pushdown Automata (2015/11/23) Chapter 6 Pushdown Automata (2015/11/23) Sagrada Familia, Barcelona, Spain Outline 6.0 Introduction 6.1 Definition of PDA 6.2 The Language of a PDA 6.3 Euivalence of PDA s and CFG s 6.4 Deterministic PDA

More information

Lecture 17: Language Recognition

Lecture 17: Language Recognition Lecture 17: Language Recognition Finite State Automata Deterministic and Non-Deterministic Finite Automata Regular Expressions Push-Down Automata Turing Machines Modeling Computation When attempting to

More information

Solution Scoring: SD Reg exp.: a(a

Solution Scoring: SD Reg exp.: a(a MA/CSSE 474 Exam 3 Winter 2013-14 Name Solution_with explanations Section: 02(3 rd ) 03(4 th ) 1. (28 points) For each of the following statements, circle T or F to indicate whether it is True or False.

More information

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4 Chomsky Normal Form and TURING MACHINES TUESDAY Feb 4 CHOMSKY NORMAL FORM A context-free grammar is in Chomsky normal form if every rule is of the form: A BC A a S ε B and C aren t start variables a is

More information

Notes for Comp 497 (454) Week 10

Notes for Comp 497 (454) Week 10 Notes for Comp 497 (454) Week 10 Today we look at the last two chapters in Part II. Cohen presents some results concerning the two categories of language we have seen so far: Regular languages (RL). Context-free

More information

The View Over The Horizon

The View Over The Horizon The View Over The Horizon enumerable decidable context free regular Context-Free Grammars An example of a context free grammar, G 1 : A 0A1 A B B # Terminology: Each line is a substitution rule or production.

More information

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor 60-354, Theory of Computation Fall 2013 Asish Mukhopadhyay School of Computer Science University of Windsor Pushdown Automata (PDA) PDA = ε-nfa + stack Acceptance ε-nfa enters a final state or Stack is

More information

CSE 355 Test 2, Fall 2016

CSE 355 Test 2, Fall 2016 CSE 355 Test 2, Fall 2016 28 October 2016, 8:35-9:25 a.m., LSA 191 Last Name SAMPLE ASU ID 1357924680 First Name(s) Ima Regrading of Midterms If you believe that your grade has not been added up correctly,

More information

Theory of Computation (IV) Yijia Chen Fudan University

Theory of Computation (IV) Yijia Chen Fudan University Theory of Computation (IV) Yijia Chen Fudan University Review language regular context-free machine DFA/ NFA PDA syntax regular expression context-free grammar Pushdown automata Definition A pushdown automaton

More information

The Pumping Lemma for Context Free Grammars

The Pumping Lemma for Context Free Grammars The Pumping Lemma for Context Free Grammars Chomsky Normal Form Chomsky Normal Form (CNF) is a simple and useful form of a CFG Every rule of a CNF grammar is in the form A BC A a Where a is any terminal

More information

Computational Models - Lecture 5 1

Computational Models - Lecture 5 1 Computational Models - Lecture 5 1 Handout Mode Iftach Haitner and Yishay Mansour. Tel Aviv University. April 10/22, 2013 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

More information

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where Recitation 11 Notes Context Free Grammars Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x A V, and x (V T)*. Examples Problem 1. Given the

More information

5 Context-Free Languages

5 Context-Free Languages CA320: COMPUTABILITY AND COMPLEXITY 1 5 Context-Free Languages 5.1 Context-Free Grammars Context-Free Grammars Context-free languages are specified with a context-free grammar (CFG). Formally, a CFG G

More information

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF) CS5371 Theory of Computation Lecture 7: Automata Theory V (CFG, CFL, CNF) Announcement Homework 2 will be given soon (before Tue) Due date: Oct 31 (Tue), before class Midterm: Nov 3, (Fri), first hour

More information

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Notes for Comp 497 (Comp 454) Week 10 4/5/05 Notes for Comp 497 (Comp 454) Week 10 4/5/05 Today look at the last two chapters in Part II. Cohen presents some results concerning context-free languages (CFL) and regular languages (RL) also some decidability

More information

Computational Models: Class 5

Computational Models: Class 5 Computational Models: Class 5 Benny Chor School of Computer Science Tel Aviv University March 27, 2019 Based on slides by Maurice Herlihy, Brown University, and modifications by Iftach Haitner and Yishay

More information

Please give details of your answer. A direct answer without explanation is not counted.

Please give details of your answer. A direct answer without explanation is not counted. Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to

More information

Properties of context-free Languages

Properties of context-free Languages Properties of context-free Languages We simplify CFL s. Greibach Normal Form Chomsky Normal Form We prove pumping lemma for CFL s. We study closure properties and decision properties. Some of them remain,

More information

Part I: Definitions and Properties

Part I: Definitions and Properties Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States

More information

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata

Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Harvard CS 121 and CSCI E-207 Lecture 10: Ambiguity, Pushdown Automata Salil Vadhan October 4, 2012 Reading: Sipser, 2.2. Another example of a CFG (with proof) L = {x {a, b} : x has the same # of a s and

More information

Pushdown Automata. Reading: Chapter 6

Pushdown Automata. Reading: Chapter 6 Pushdown Automata Reading: Chapter 6 1 Pushdown Automata (PDA) Informally: A PDA is an NFA-ε with a infinite stack. Transitions are modified to accommodate stack operations. Questions: What is a stack?

More information

The Turing Machine. Computability. The Church-Turing Thesis (1936) Theory Hall of Fame. Theory Hall of Fame. Undecidability

The Turing Machine. Computability. The Church-Turing Thesis (1936) Theory Hall of Fame. Theory Hall of Fame. Undecidability The Turing Machine Computability Motivating idea Build a theoretical a human computer Likened to a human with a paper and pencil that can solve problems in an algorithmic way The theoretical provides a

More information

October 6, Equivalence of Pushdown Automata with Context-Free Gramm

October 6, Equivalence of Pushdown Automata with Context-Free Gramm Equivalence of Pushdown Automata with Context-Free Grammar October 6, 2013 Motivation Motivation CFG and PDA are equivalent in power: a CFG generates a context-free language and a PDA recognizes a context-free

More information

Theory of Computation (II) Yijia Chen Fudan University

Theory of Computation (II) Yijia Chen Fudan University Theory of Computation (II) Yijia Chen Fudan University Review A language L is a subset of strings over an alphabet Σ. Our goal is to identify those languages that can be recognized by one of the simplest

More information

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules). 1a) G = ({R, S, T}, {0,1}, P, S) where P is: S R0R R R0R1R R1R0R T T 0T ε (S generates the first 0. R generates

More information

Languages, regular languages, finite automata

Languages, regular languages, finite automata Notes on Computer Theory Last updated: January, 2018 Languages, regular languages, finite automata Content largely taken from Richards [1] and Sipser [2] 1 Languages An alphabet is a finite set of characters,

More information

Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage?

Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage? Turing machines Finite automaton no storage Pushdown automaton storage is a stack What if we give the automaton a more flexible storage? What is the most powerful of automata? In this lecture we will introduce

More information

Theory & Practice Book. Computer Science & IT. for. Public Sector Exams

Theory & Practice Book. Computer Science & IT. for. Public Sector Exams Theory & Practice Book Computer Science & IT for Public Sector Exams ISRO, DRDO, BARC, BEL, HAL, NTPC, ONGC, BHEL, SAIL, GAIL, MTNL, FCI, ECL, ATC, DMRC, HLL, UPRVNL, CSPEB, OPTCL... Corporate Office:

More information

Properties of Context-Free Languages. Closure Properties Decision Properties

Properties of Context-Free Languages. Closure Properties Decision Properties Properties of Context-Free Languages Closure Properties Decision Properties 1 Closure Properties of CFL s CFL s are closed under union, concatenation, and Kleene closure. Also, under reversal, homomorphisms

More information

Computational Models - Lecture 3

Computational Models - Lecture 3 Slides modified by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p. 1 Computational Models - Lecture 3 Equivalence of regular expressions and regular languages (lukewarm leftover

More information

CS21 Decidability and Tractability

CS21 Decidability and Tractability CS21 Decidability and Tractability Lecture 8 January 24, 2018 Outline Turing Machines and variants multitape TMs nondeterministic TMs Church-Turing Thesis So far several models of computation finite automata

More information

Chap. 7 Properties of Context-free Languages

Chap. 7 Properties of Context-free Languages Chap. 7 Properties of Context-free Languages 7.1 Normal Forms for Context-free Grammars Context-free grammars A where A N, (N T). 0. Chomsky Normal Form A BC or A a except S where A, B, C N, a T. 1. Eliminating

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.3, 4.1 State and use the Church-Turing thesis. Give examples of decidable problems.

More information

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class CSE 105 THEORY OF COMPUTATION Spring 2018 review class Today's learning goals Summarize key concepts, ideas, themes from CSE 105. Approach your final exam studying with confidence. Identify areas to focus

More information

Fundamentele Informatica II

Fundamentele Informatica II Fundamentele Informatica II Answer to selected exercises 5 John C Martin: Introduction to Languages and the Theory of Computation M.M. Bonsangue (and J. Kleijn) Fall 2011 5.1.a (q 0, ab, Z 0 ) (q 1, b,

More information

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach CS311 Computational Structures More about PDAs & Context-Free Languages Lecture 9 Andrew P. Black Andrew Tolmach 1 Three important results 1. Any CFG can be simulated by a PDA 2. Any PDA can be simulated

More information

MA/CSSE 474 Theory of Computation

MA/CSSE 474 Theory of Computation MA/CSSE 474 Theory of Computation Bottom-up parsing Pumping Theorem for CFLs Recap: Going One Way Lemma: Each context-free language is accepted by some PDA. Proof (by construction): The idea: Let the stack

More information

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008

CS Lecture 28 P, NP, and NP-Completeness. Fall 2008 CS 301 - Lecture 28 P, NP, and NP-Completeness Fall 2008 Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata Equivalence of

More information

SFWR ENG 2FA3. Solution to the Assignment #4

SFWR ENG 2FA3. Solution to the Assignment #4 SFWR ENG 2FA3. Solution to the Assignment #4 Total = 131, 100%= 115 The solutions below are often very detailed on purpose. Such level of details is not required from students solutions. Some questions

More information