Theory of Computation

Similar documents
2.1 Solution. E T F a. E E + T T + T F + T a + T a + F a + a

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Computational Models - Lecture 4

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Finite Automata and Regular Languages

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 5 : DFA minimization

DM17. Beregnelighed. Jacob Aae Mikkelsen

Theory Bridge Exam Example Questions

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

Theory of Computation (Classroom Practice Booklet Solutions)

CS 133 : Automata Theory and Computability

Context-Free Languages (Pre Lecture)

Closure under the Regular Operations

CSE 355 Test 2, Fall 2016

Fundamentele Informatica II

10. The GNFA method is used to show that

Pushdown Automata. Reading: Chapter 6

Automata: a short introduction

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 9 : Myhill-Nerode Theorem and applications

5 Context-Free Languages

More Properties of Regular Languages

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

Formal Languages, Automata and Models of Computation

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Name: Student ID: Instructions:

Computational Models - Lecture 3 1

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

Computational Models - Lecture 5 1

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Pushdown Automata (2015/11/23)

Computational Models: Class 3

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

What we have done so far

CISC4090: Theory of Computation

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

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

MA/CSSE 474 Theory of Computation

Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

CS 154 Introduction to Automata and Complexity Theory

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

CSE 105 THEORY OF COMPUTATION

CPSC 421: Tutorial #1

CSE 105 THEORY OF COMPUTATION

Section 1 (closed-book) Total points 30

Einführung in die Computerlinguistik

Nondeterministic Finite Automata

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

HW6 Solutions. Micha l Dereziński. March 20, 2015

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

CS481F01 Prelim 2 Solutions

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

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

Computational Models - Lecture 3

Computational Models - Lecture 4 1

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.

CPS 220 Theory of Computation

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

Foundations of Informatics: a Bridging Course

Context-Free and Noncontext-Free Languages

ECS120 Fall Discussion Notes. October 25, The midterm is on Thursday, November 2nd during class. (That is next week!)

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2017

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

Theory of Computation (IV) Yijia Chen Fudan University

CSE 105 THEORY OF COMPUTATION

Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

CpSc 421 Final Exam December 15, 2006

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL)

The View Over The Horizon

Properties of Context-Free Languages. Closure Properties Decision Properties

ÖVNINGSUPPGIFTER I SAMMANHANGSFRIA SPRÅK. 17 april Classrum Edition

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Theory of Computation

Fooling Sets and. Lecture 5

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CS 455/555: Finite automata

CS154 Final Examination

Fundamentele Informatica 3 Antwoorden op geselecteerde opgaven uit Hoofdstuk 7 en Hoofdstuk 8

Context-free Languages and Pushdown Automata

Automata and Computability. Solutions to Exercises

Pushdown Automata: Introduction (2)

CS5371 Theory of Computation. Lecture 9: Automata Theory VII (Pumping Lemma, Non-CFL, DPDA PDA)

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Theory of Computation Lecture 1. Dr. Nahla Belal

COMP-330 Theory of Computation. Fall Prof. Claude Crépeau. Lec. 10 : Context-Free Grammars

Author: Vivek Kulkarni ( )

3130CIT Theory of Computation

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

Automata and Computability. Solutions to Exercises

3515ICT: Theory of Computation. Regular languages

Transcription:

Fall 2002 (YEN) Theory of Computation Midterm Exam. Name:... I.D.#:... 1. (30 pts) True or false (mark O for true ; X for false ). (Score=Max{0, Right- 1 2 Wrong}.) (1) X... If L 1 is regular and L 2 L 1, then L 2 is regular as well. counterexample L 1 = {a} and L 2 = {a p p is prime} L 1 is regular and L 2 L 1, but L 2 is not regular (2) X... If L 1 is regular and L 2 is not regular, then L 1 L 2 is not regular. counterexample L 1 = {a} and L 2 = {a p p is prime} L 1 is regular and L 2 is not regular, but L 1 L 2 is regular (3) O... If L 1 is regular and L 1 L 2 is not regular, then L 2 is not regular. we know that regular language is closed under union, i.e., L 1 is regular L 2 is regular = L 1 L 2 is regular Now the right hand side of the proposition above is not true, so L 1 or L 2 is not regular. With the fact that L 1 is regular, L 2 is not regular. (4) X... If L 1 is regular and L 2 is not regular, then L 1 L 2 is not regular. counterexample L 1 = φ and L 2 = {a p p is prime} L 1 L 2 = φ is regular (5) X... If L 1 and L 1 L 2 are regular, then L 2 must be regular. counterexample L 1 = φ and L 2 = {a p p is prime} L 1 L 2 = L 1 L 2 = φ L 2 = φ is regular, but L 2 is not regular. (6) X... {a i b i+j c j i, j 0} is regular. (7) X... {(a n b) n n 1} is context free. (8) X... {(a n b) m m, n 1} is context free. 1

(9) O... {a m b n c p d q m + n = p + q} is context free. (10) O... {wcw R cw w {a, b} } ( {a, b, c} ) can be represented as the intersection of two context free languages. It can be represented as the intersection of the following two context-free languages L 1 = {ωcxcω ω, x {a, b} } L 2 = {ωcω R cx ω, x {a, b} } (11) O... We define L 1 /L 2 ={x y L 2, such that xy L 1 }. If both L 1 and L 2 are regular, so is L 1 /L 2. (12) X... If L 1 /L 2 and L 1 are context free, then L 2 must be regular. (13) X... {a m b n m, n 1}/{b n n 1}={a m m 1}. It should be {a m b m 1} (14) X... If L 1 is regular and L 2 is not regular, then L 1 L 2 (the concatenation of L 1 and L 2 ) cannot be regular. (15) O... If L 1 is context-free and L 2 is regular, then L 1 L 2 is context free. See problem 2.(f) (16) X... If L 1 is regular and L 2 is context free, then L 1 L 2 is context free. See problem 2.(f) (17) O... If L is context free, then L R (={x R x L}) is also context free. we can always find a CFG to produce L R : by replacing the string on right-hand-side of every production rule with its reverse, for example, if L is produced by the grammar G: then L R can be produced by G R : A 01B B 2# A B10 B #2 which is made by replacing 01B on the RHS of first production rule of G with B10, and replacing 2# with #2 in the second rule. (18) O... {xxxx x {0, 1} } can be accepted by a nondeterministic linear bounded 2

automaton (LBA). (19) O... Let L( Σ ) be a regular language. Then Enlarge(L)={x Σ for some y Σ, xy L} is also regular. (20) O... Every regular language can be accepted by some NFA with exactly 15 final states. Every regular language can be accepted by some NFA, which might has an arbitrary number of final states. We can turn it into an NFA with exactly one final state, and then an NFA with exactly 15 final states: (a) Introduce a new state into the NFA, and add λ transitions from every final state to it. (b) Replace the NFA s set of final state with the set that consists of only the newly introduced state. That is, the newly introduced state is now the only one designated as the final state. The resulted NFA is equivalent to the original one, but has exactly one final state. (c) Introduce another 14 states into the NFA, and add λ transitions from the only one final state to them. Then designate the 14 new states as the final states as well. Now the NFA is equivalent ot the original one, but has exactly 15 final states. (21) O... For every n, L n = {a i b i i n} is regular. It s regular because it s finite. (22) X... Nondeterministic and deterministic versions of PDAs are equivalent. Example 2.10 on p.105 of the textbook tells us that it s not the case. (23) X... If a language L satisfies the conditions stated in the pumping lemma for CFLs, then L is context free. Pumping lemma is a necessary condition, but not a sufficient one! (24) X... Every infinite set of strings over a single letter alphabet Σ (={a}) contains an infinite context free subset. (25) X... L 1 = L 2 if and only if L 1 = L 2. counterexample let L 1 = {a, aa}, L 2 = {a p p is 1 or is prime} L 1 L 2, but L 1 = L 2 = a (26) O... For any languages L 1, L 2 and L 3, L 1 (L 2 L 3 ) (L 1 L 2 ) (L 1 L 3 ) see the next problem (27) X... For any languages L 1, L 2 and L 3, (L 1 L 2 ) (L 1 L 3 ) L 1 (L 2 L 3 ). counterexample let L 1 = {a, aa}, L 2 = {a i i is odd}, L 3 = {a i i is even}; (L 1 L 2 ) (L 1 L 3 ) = {a}, L 1 (L 2 L 3 ) = φ 3

(28) O Every non-regular language is infinite.... because for every finite language, we can construct a finite state automaton to accept it. (29) X A context-free language is inherently ambiguous iff there exists... an ambiguous context-free grammar generating the language. by definition, inherently ambiguous context-free languages are languages that can only be generated by ambiguous grammars. (30) X... The intersection of two non-context-free languages cannot be context-free. counterexample The intersection of the following two non-context-free languages {a i b i c i i 0} and is φ, which is context-free. {a i b j c i 1 < i < j < 2i} 4

2. (30 pts) Answer the following questions. (a) (3 pts) Let F LIP (A) = {ww R w A}. (w R denotes the reversal of w.) Is there a regular language X such that F LIP (X) is not regular? Why? If X = {10 i 1 i 0}, then F LIP (X) = {10 i 110 i 1 ı 0}, which is not regular. (b) (3 pts) Write down the set of strings expressed by the regular expression: (λ 0 10)(λ 1). (λ denotes the empty string, and 0 and 1 are two symbols.) {λ, 0, 1, 01, 10, 101} (c) (3 pts) Define conf igurations for finite automata and pushdown automata. for FSA: current state & rest of the input string for PDA: current state & rest of the input string & current stack content (d) (3 pts) Eliminate the λ rule in the following CFG (i.e., write down an equivalent one without the λ rule). S AAA A a b λ S aaa aab aba abb baa bab bba bbb aa ab ba bb a b λ or S AAA AA A λ A a b (e) (4 pts) List four operations under which the context-free languages are closed. Union, concatenation, star, reverse (f) (8 pts) Suppose L is context-free and R is regular. (1) Is L R context-free? Why? It is known that regular language is closed under complement and that CFL is closed under intersection with regular languages. L R = L R, so L R is context-free (2) Is R L context-free? Why? It is known that CFL is NOT closed under complement and that CFL is closed under intersection with regular languages. R L = R L, so R L is not necessarily context-free (g) (6 pts) (1) State Myhill-Nerode theorem. A language L over alphabet Σ is non-regular there is an infinite subset of Σ such that for each pair of string x and y in it, exactly one of xz and yz is in L for some z Σ. 5

(2) Instead of using the pumping lemma, use Myhill-Nerode theorem to show {ww w Σ } to be non-regular. L = {ww w Σ }. A non-regularity proof by Myhill-Nerode requires finding an infinite set S of strings and a string for each pair of strings of S. Consider the set of string S = {a i i N}. Let a m and a n be arbitrary two different members of S, where m, n N and m n. Select ba m b as a string to be appended to a m and a n, then a m ba m b is in L while a n ba m b is not. Since a m and a n are an arbitrary pair of strings of S, S satisfies the conditions of Myhill-Nerode theorem. Hence L is non-regular. 3. (10 pts) Let L = {a i b j c i i j 2i}. Prove that L is NOT context-free. Assume that L is a CFL and obtain a contradiction. Let p be the pumping length for L that is guaranteed to exist by the pumping lemma. Select the string s = a p b p c p. Clearly s is a member of L and of length at least p. Condition 3 says that vxy p, which implies the following five cases: a. vxy lies entirely within a p (or c p ): pumping s up or down will make the number of a not eqaul to the number of c, and therefore not a member of L. Condition 1 is violated and a contradiction occurs. b. v (y) contains only characters of a (c), and y (v) contains characters of a and b (b and c): pumping s up will make the string of the form a x b y a z b u c v (a x b y c z b u c v ), and therefore not a member of L. Condition 1 is violated and a contradiction occurs. c. v (y) contains only characters of a (c), and y (v) contains only characters of b: pumping s up or down will make the number of a not eqaul to the number of c, and therefore not a member of L. Condition 1 is violated and a contradiction occurs. d. v (y) contains characters of a and b (b and c), and y (v) contains only characters of b: similar to case b.. e. vxy lies entirely within b p : pumping s up will make the number of b more than two times the number of a, and therefore not a member of L. That violates condition 1 of the lemma and is thus a contradiction. 4. (10 pts) Consider the infinite 2-dimensional grid G = {(m, n) m and n are integers}. Every point in G has 4 neighbors, North, South, East, and W est. Starting at the origin (0, 0), a string of commands N, S, E, W generates a path in G. For instance the string NESW generates a path clockwise around a unit square touching the origin. Say that a path is closed if it starts at the origin and ends at the origin. Let C be the set of all strings over Σ = {N, S, E, W } that generate a closed path. (a) Is C context-free? Give a convincing proof. 6

C is the set of strings in which #(N) = #(S) and #(E) = #(W ) Assume that C is a CFL and obtain a contradiction using the pumping lemma. Let p be the pumping length for C that is guaranteed to exist by the pumping lemma. Select the string s = N p E p S p W p. Clearly s is a member of C and of length at least p. By condition 3 of the pumping lemma ( vxy p), it is easily seen that v and y can only contain at most two kinds of commands next to each other (N and E, E and S, or S and W), and pumping s will cause #(N) #(S) or #(E) #(W ), which violates the condition 1 and a contradiction occurs. (b) Describe in English two CFLs A and B, such that C = A B. A is a CFL in which every string has an equal number of N and S. B is a CFL in which every string has an equal number of E and W. 5. (10 pts) (1) Let B={1 k y y {0, 1}, y contains at least k 1s, for k 1}. Show that B is regular. 1 k y = 11 k 1 y = 1z, where z = 1 k 1 y. z contains at least (k 1) + k = 2k 1 1s, where k 1. And since k 1, (2k 1) (2 1 1) = 1 B={1 k y y {0, 1}, y contains at least k 1s, for k 1}={1z z {0, 1}, z contains at least one 1}, which can be easily checked by a FSA. (2) Let C={1 k y y {0, 1}, y contains at most k 1s, for k 1}. Show that C is NOT regular. Assume that C is regular and obtain a contradiction. Let p be the pumping length for C that is guaranteed to exist by the pumping lemma. Select the string s = 1 p 01 p. Clearly s is a member of C and of length at least p. Condition 3 of the pumping lemma says xy p, which implies that y lies entirely within the front 1 p. Pumping s down will make the 1s in y outnumber those in the front 1 p. A contradiction occurs. 6. (10 pts) You are given two DFAs M 1 = (Q 1, Σ, δ 1, q 1, F 1 ) and M 2 = (Q 2, Σ, δ 2, q 2, F 2 ). Suppose you want to construct a DFA M = (Q, Σ, δ, q, F ) to accept L(M 1 ) L(M 2 ) (i.e., the set of strings that are in L(M 1 ) but are not in L(M 2 )). Suppose you use the product construction, so Q = Q 1 Q 2. Write down δ, q, and F precisely. δ((x, y), a) = (δ 1 (x, a), δ 2 (y, a)), where (x, y) (Q 1 Q 2 ), and a Σ q = (q 1, q 2 ) F = F 1 (Q 2 F 2 ) 7. (10 pts) A Deterministic Counter Automaton (DCA) is a deterministic pushdown automaton whose stack alphabet consists of just one symbol. Just like a PDA, at every transition a DCA can push or pop a symbol from the stack, and can test for the stack being empty. (a) Give a non-regular language accepted by a DCA. L = {a i b i i N} 7

(b) Is the language L = {w#w R w {0, 1} } accepted by a DCA? Prove it. (Hint: How many configurations are possible for a DCA when it reaches #?) There are 2 w possibilities for a string of length w. And it implies that there must be 2 w different configurations for the machine to remember the string it reads so far. However, from the structure of DCA, we know that the DCA can only offer at most Q w different configurations (even if it changes states and pushes or pops the stack every time it reads a character), where Q is the number of states the DCA has, which is finite. 2 w will outnumber Q w when w grows long enough. With pigeon hole principle, we know that it s impossible for a DCA to accept L. 8