Automata Theory - Quiz II (Solutions)

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

Part I: Definitions and Properties

ECS 120 Lesson 15 Turing Machines, Pt. 1

Fundamentele Informatica II

Turing Machines A Turing Machine is a 7-tuple, (Q, Σ, Γ, δ, q0, qaccept, qreject), where Q, Σ, Γ are all finite

Languages, regular languages, finite automata

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computability and Complexity

ECS 120 Lesson 20 The Post Correspondence Problem

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

CISC4090: Theory of Computation

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

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

Theory of Computation (IV) Yijia Chen Fudan University

Pushdown Automata. We have seen examples of context-free languages that are not regular, and hence can not be recognized by finite automata.

Ogden s Lemma for CFLs

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Theory of Computation Turing Machine and Pushdown Automata

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

SCHEME FOR INTERNAL ASSESSMENT TEST 3

CSE 105 THEORY OF COMPUTATION

Chomsky Normal Form and TURING MACHINES. TUESDAY Feb 4

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Foundations of Informatics: a Bridging Course

Theory of Computation (Classroom Practice Booklet Solutions)

DM17. Beregnelighed. Jacob Aae Mikkelsen

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

(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},

The Pumping Lemma. for all n 0, u 1 v n u 2 L (i.e. u 1 u 2 L, u 1 vu 2 L [but we knew that anyway], u 1 vvu 2 L, u 1 vvvu 2 L, etc.

Automata Theory CS S-12 Turing Machine Modifications

Undecidable Problems and Reducibility

Homework. Context Free Languages. Announcements. Before We Start. Languages. Plan for today. Final Exam Dates have been announced.

Chapter 3: The Church-Turing Thesis

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

Properties of Context-Free Languages. Closure Properties Decision Properties

Chapter 8. Turing Machine (TMs)

Introduction to Languages and Computation

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

MA/CSSE 474 Theory of Computation

NPDA, CFG equivalence

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

Decidable and undecidable languages

Turing machines COMS Ashley Montanaro 21 March Department of Computer Science, University of Bristol Bristol, UK

CS Pushdown Automata

PS2 - Comments. University of Virginia - cs3102: Theory of Computation Spring 2010

Pushdown Automata: Introduction (2)

Theory of Computation

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

CPSC 421: Tutorial #1

Rumination on the Formal Definition of DPDA

1 Unrestricted Computation

Introduction to Theory of Computing

Harvard CS 121 and CSCI E-121 Lecture 14: Turing Machines and the Church Turing Thesis

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Analysis of Algorithms - Midterm (Solutions)

Theory of Computation - Module 4

CS21 Decidability and Tractability

Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. Pushdown Automata. The stack

Solution Scoring: SD Reg exp.: a(a

Turing Machine properties. Turing Machines. Alternate TM definitions. Alternate TM definitions. Alternate TM definitions. Alternate TM definitions

Accept or reject. Stack

5 Context-Free Languages

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

C6.2 Push-Down Automata

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

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

Computability and Complexity

Computational Models - Lecture 4

Notes for Comp 497 (Comp 454) Week 12 4/19/05. Today we look at some variations on machines we have already seen. Chapter 21

The Power of One-State Turing Machines

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

Finite Automata Theory and Formal Languages TMV026/TMV027/DIT321 Responsible: Ana Bove

Theory of Computation

Computability Theory. CS215, Lecture 6,

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

SFWR ENG 2FA3. Solution to the Assignment #4

Outline 1 PCP. 2 Decision problems about CFGs. M.Mitra (ISI) Post s Correspondence Problem 1 / 10

Pushdown Automata. Chapter 12

Designing 1-tape Deterministic Turing Machines

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

Homework 8. a b b a b a b. two-way, read/write

Turing Machines Part II

Blackhole Pushdown Automata

Busch Complexity Lectures: Turing Machines. Prof. Busch - LSU 1

CSCC63 Worksheet Turing Machines

UNIT-VI PUSHDOWN AUTOMATA

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.

Fundamentals of Computer Science

Theory of Computation - Module 3

CS154 Final Examination

Turing Machines Part III

Variants of Turing Machine (intro)

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

Automata and Computability. Solutions to Exercises

Chapter 7 Turing Machines

Pushdown Automata (2015/11/23)

Transcription:

Automata Theory - Quiz II (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu} 1 Problems 1. Induction: Let L denote the language of balanced strings over Σ = {0, 1}, i.e., L consists of all strings in {0, 1}, such that n 0 (w) = n 1 (w). Given a string w = w 1 w 2... w n, a proper prefix of w is defined to be any string x = x 1 x 2... x k, such that k < n and x i = w i, i = 1, 2,..., k. Let y = y 1 y 2... y r denote an arbitrary string in L with y 1 = y r. Argue that y must have a balanced proper prefix. Solution: We use induction on y to prove the theorem. The following observations are in order: (a) y must be even. (Straightforward proof using induction.) (b) y 4. If y = 0, then y = λ; if y = 2, then y must be 01 or 10 and hence the first and last characters are not equal. Accordingly, the base case is y = 4; the restriction that y 1 = y 4, implies that y is either 0110 or 1001. In the former case, 01 is the balanced proper prefix, while in the latter case, 10 is. Thus, in both cases, inspection establishes the existence of a balanced proper prefix and the basis is proven. Assume that the theorem holds true for all balanced strings y, where y 4 + 2 r, r 0. Now consider a balanced string y of length y = 4 + 2ṙ + 2. Without loss of generality, assume that y 1 = y 4+2 r+2 = 0. Accordingly, y has the form 0w0, where w = w 1 w 2... w 4+2 r. Since y is balanced, w contains at least one position i such that w i = 1. Let m denote the smallest such position, i.e., w i = 0, i = 1, 2,..., m 1. Consider the string y obtained from y, by eliminating the substring z = 0w m. Clearly, y is balanced; further y = 4 + 2 r and hence, as per the inductive hypothesis, y has a balanced proper prefix, say y. Reinserting z into y at the appropriate positions, gives us a balanced proper prefix of y. Applying the principle of mathematical induction, we conclude that the theorem is true. 2. Context-Free Grammars: Consider the grammar G = V, T, S, P, where V = {S}, T = {0, 1}, S = S, and the productions P are defined by: S 0S1 1S0 SS λ Argue that L(G) contains the set of all balanced strings. Solution: Let x denote an arbitrary balanced string; we used induction on x to show that x can be derived from S. BASIS: x = 0. In this case, x must be λ and since S λ is a production of the grammar, we have proved that S x. INDUCTIVE STEP: Assume that if x is a balanced string of length at most 2 k, then S x. Now consider a string x of length 2 k + 2, k 0. We need to consider the following cases: 1

(i) x 1 = 0 and x 2 k+2 = 1 In this case, x has the form 0w1, where w is also balanced. However, since w = 2 k, as per the inductive hypothesis, w can be derived from S. But this immediately implies that x can be derived from S; for instance, S 0S1 0w1 x. (ii) x 1 = 1 and x 2 k+2 = 0 This case is identical to the one above. (iii) x 1 = 0 and x 2 k+2 = 0 In this case, we know from the prefix theorem, that x must have a balanced proper prefix. Let us call this prefix y. Then x can be written as y y, where y is also balanced. Since y, y 2 k, we know that y and y can be derived from S. Thus x can be derived from S as follows: S SS ys y y x. (iv) x 1 = 1 and x 2 k+2 = 1 This case is identical to the one above. Applying the principle of mathematical induction, we conclude that all balanced strings can be derived from S, i.e., L(G) contains the set of all balanced strings. 3. Context-Free Grammar Parsing: Consider the grammar G = V, T, S, P, with V = {S, A, B, C}, T = {a, b}, S = S and the productions P defined by: S AB BC A BA a B CC b C AB a Use the CYK algorithm to establish the membership or non-membership of w = ababa in L(G). (You may not use trial and error!) Solution: Table (1) represents the application of the CYK algorithm to determine the membership of w = ababa in L(G). Table 1: Applying the CYK algorithm {S} {B} {B} {B} {S, C} {B} {S, C} {A, C} {S, C} {A, C} {A, C} {B} {A, C} {B} {A, C} a b a b a Since the topmost leftmost entry contains the start symbol S, we conclude that w L(G); indeed the following leftmost derivation establishes it. S AB ab acc aabc ababc ababc ababc ababc ababa 2

4. Pushdown Automaton Design: Consider the language L defined as follows: L = {w {0, 1} : n 0 (w) = 2 n 1 (w)}. Establish that L is context-free by designing a PDA that accepts all and only those strings in L. Solution: In design problems, it is helpful to identify the strategy first. One approach to designing an accepter for L is as follows: Mark the occurrence of a 1 with two X characters and mark the occurrence of a 0 with a single Y character. If the input string w contains twice as many 0s as 1s, then it must be the case that the number of X characters equals the number of Y characters. Consider the following non-deterministic PDA M = Q, Σ, Γ, δ, q 0, z, F, where, (i) Q = {q 0, q 1, q f }. (ii) Σ = {0, 1}. (iii) Γ = {X, Y, z}. (iv) δ is defined through the following transitions: (a) If there is no input at all, i.e., w = λ, then n 0 (w) = 2 n 1 (w). Accordingly, we have, δ(q 0, λ, z) = (q f, λ) (b) When the input character is 0, we first check if there are any 1s on the stack to match it with; if not, Y is pushed onto the stack. Accordingly, we have, δ(q 0, 0, z) = (q 0, Y z) δ(q 0, 0, X) = (q 0, λ) δ(q 0, 0, Y ) = (q 0, Y Y ) (c) When the input character is a 1, we first check if there are any 0s on the stack to match it with; if not, we push in two X characters onto the stack. The matching portion needs to be carried out carefully, since there are various character combinations on the stack, which must be accounted for. Accordingly, we have, δ(q 0, 1, z) = (q 0, XXz) δ(q 0, 1, X) = (q 0, XXX) δ(q 0, 1, Y ) = (q 1, λ) δ(q 1, λ, Y ) = (q 0, λ) δ(q 1, λ, X) = (q 0, XX) δ(q 1, λ, z) = (q 0, Xz) (v) q 0 = q 0. (vi) z = z. (vii) F = {q f }. The above design reinforces the power of non-determinism; if we had chosen to design a DPDA for L, the task would have been onerous indeed. It is a straightforward exercise using induction to establish that L = L(M). 3

5. Turing Machine Design: Design a Deterministic Turing Machine to decide the language of palindromes over {0, 1}. You may select the architecture of the Turing Machine, as per your tastes and convenience. Solution: I choose a two-tape Turing Machine in which the tapes are semi-infinite, i.e., unbounded only on the left. The left end of each tape is marked by the special character. The algorithm consists of the following steps: (a) Copy the input string w which is on the first tape onto the second tape. (b) Position the head of the first tape on the first symbol after, i.e., the first symbol of w and the head of the second tape on the last symbol of w. (c) As long as the symbols under both heads are identical, move the first tape head to the right and the second tape head to the left. If at any point, the tape heads read different symbols, halt and reject. Likewise, if the first tape head encounters a blank, then halt and accept. Note that the occurrence of a blank below the first tape head coincides with the occurrence of below the second tape head. The above design makes the following assumptions: (a) The input string is written on the first tape immediately after the, (b) At commencement, both tape heads are on the symbols of their respective tapes, (c) The second tape is initially blank, (d) On each transition, the tape heads can independently move right ( ), left ( ) or stay put ( ). Consider the Turing Machine M = Q, Σ, Γ, δ, q 0,, F, where, (i) Q = {q 0, q 1, q 2, q 3, q 4 }. (ii) Σ = {0, 1}. (iii) Γ = {0, 1,, }. (iv) The program δ is defined by the following transitions: (a) The first set of transitions copies the input string onto the second tape. Accordingly, we have, δ(q 0, 0, ) = (q 0, 0,, 0, ) δ(q 0, 1, ) = (q 0, 1,, 1, ) δ(q 0,, ) = (q 0,,,, ) (b) The second set of transitions repositions the heads of both tapes. Accordingly, we have, δ(q 0,, ) = (q 1,,,, ) δ(q 1, 0, ) = (q 1, 0,,, ) δ(q 1, 1, ) = (q 1, 1,,, ) δ(q 1,, ) = (q 2,,,, ) (c) The third set of transitions accomplishes the match and move portion of our algorithm. Accordingly, we have, δ(q 2, 0, 0) = (q 2, 0,, 0, ) δ(q 2, 1, 1) = (q 2, 1,, 1, ) δ(q 2,, ) = (q 3,,,, ) 4

(d) The final set of transitions accounts for the case in which w is not a palindrome. Accordingly, we have, δ(q 2, 0, 1) = (q 4, 0,, 1, ) δ(q 2, 1, 0) = (q 4, 1,, 0, ) (v) q 0 = q 0. (vi) =. (vii) F = {q 3 }. We observe that q 3 is the accept state, while q 4 is the reject state. It is not hard to see that the above Turing Machine accomplishes the mission of recognizing palindromes. I do expect that you will formally argue the correctness of the design using induction. 5