Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Similar documents
Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Deterministic Finite Automata

Harvard University Computer Science 121 Midterm October 23, 2012

First Midterm Examination

Non-deterministic Finite Automata

Formal languages, automata, and theory of computation

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Minimal DFA. minimal DFA for L starting from any other

First Midterm Examination

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Name Ima Sample ASU ID

Worked out examples Finite Automata

Theory of Computation Regular Languages

CS 330 Formal Methods and Models

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

Non-deterministic Finite Automata

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

Some Theory of Computation Exercises Week 1

Automata and Languages

Nondeterminism and Nodeterministic Automata

Formal Languages and Automata

Lecture 09: Myhill-Nerode Theorem

Regular expressions, Finite Automata, transition graphs are all the same!!

1 Nondeterministic Finite Automata

1.4 Nonregular Languages

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Homework 3 Solutions

Lecture 6 Regular Grammars

CS375: Logic and Theory of Computing

Finite-State Automata: Recap

Context-Free Grammars and Languages

CS 330 Formal Methods and Models

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

CS 275 Automata and Formal Language Theory

Finite Automata-cont d

Coalgebra, Lecture 15: Equations for Deterministic Automata

Lecture 08: Feb. 08, 2019

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

Revision Sheet. (a) Give a regular expression for each of the following languages:

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Homework Solution - Set 5 Due: Friday 10/03/08

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

Normal Forms for Context-free Grammars

CS 330 Formal Methods and Models

Convert the NFA into DFA

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

State Minimization for DFAs

CMSC 330: Organization of Programming Languages

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

1.3 Regular Expressions

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CS 275 Automata and Formal Language Theory

FABER Formal Languages, Automata and Models of Computation

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) - Spring L. Blum

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

3 Regular expressions

Let's start with an example:

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

CS375: Logic and Theory of Computing

CSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes

Tutorial Automata and formal Languages

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

CHAPTER 1 Regular Languages. Contents

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

Automata Theory 101. Introduction. Outline. Introduction Finite Automata Regular Expressions ω-automata. Ralf Huuck.

CSC 311 Theory of Computation

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

Thoery of Automata CS402

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

NFAs continued, Closure Properties of Regular Languages

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

More on automata. Michael George. March 24 April 7, 2014

Designing finite automata II

Closure Properties of Regular Languages

SWEN 224 Formal Foundations of Programming WITH ANSWERS

1 Structural induction

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Compiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

CISC 4090 Theory of Computation

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

This lecture covers Chapter 8 of HMU: Properties of CFLs

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Languages & Automata

The University of Nottingham

CS 275 Automata and Formal Language Theory

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Transcription:

Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100 points, nd ech question indictes how mny points it is worth. The test is closed ook. You re NOT llowed to use clcultor, computer or moile phone. You my nswer in Dutch or in English. Plese write clerly, nd do not forget to put on ech pge: your nme nd your student numer. Nottion Throughout the test, we denote for ny lphet A, w A nd A y w the numer of s in w, s it ws introduced in the lecture. Moreover, recll tht v is suword of w if w = xvy for some words x, y. 1 Induction Let A nd B e finite lphets nd f : A B mp from A to words over B. ) Define y induction mp f : A B tht replces in word w A ll letters y f(). (5pt) We define the required mp y f(λ) = λ f(w) = f()f(w) ) Let A = {, } nd f : A A e given y f() = nd f() =. i) Give word w A such tht f(w) =. (5pt) w = does the jo. ii) Show y induction tht f(w) = w + 2 w. We show y induction in w tht f(w) = w + 2 w. IB: w = λ. Here, we get tht f(λ) = λ = 0 = λ + 2 λ IH: For w A, f(w) = w + 2 w. IS: Let x A. We need to distinguish two cses. 1. If x =, then we hve s required. f(w) = f()f(w) = f(w) = f(w) + 1 IH = w + 2 w + 1 = w + 2 w

2. If, on the other hnd, x =, then f(w) = f()f(w) = f(w) = f(w) + 2 IH = w + 2 w + 2 = w + 2 w. So in oth cses f(xw) = xw + 2 xw. This induction proves the desired eqution. 2 Regulr Lnguges [Write your nswers on seprte pge] ) Let A = {, } nd L 1 = {w A w is even} L 2 = L ( ( + ) ( + ) ) L 3 = {w A w does not contin the suword }. Explin for ech i = 1, 2, 3 whether nd why L i = L i. L 1 = L 1, since 1. λ is even nd for ll w, v L 1 we hve wv = w + v is even; thus L 1 L 1, see 5) on exercise sheet 1. 2. L 1 L 1 holds trivilly. L 2 L 2, since λ L 2 ut not in L 2. L 3 L 3, since L 3 nd L 3, hence L 3. ) Let A = {, } nd L = {w A occurs twice s suword in w}. Give regulr expression e, such tht L (e) = L. Explin your nswer. We put e = ( + ) (( + ) +)( + ). Tht L (e) = L cn e seen s follows. To show the inclusion L L (e), let w L so tht there re x 1, y 1, x 2, y 2 A with w = x i y i nd x 1 x 2 nd y 1 y 2. WLOG, we ssume tht x 1 = x 2 z for some non-empty word z. Then either 1. z = u, u A. Then w = x 2 u y 1, hence w L (e). 2. z =. Then w = x 2 y 1, hence w L (e). The other direction cn e seen s follows. Let w L (e), then either w = xyz or w = xy. Thus we cn split in oth cses w twice into uv with u = x, v = yz nd u = xy, v = z in the first cse, nd u = x, v = y nd u = x, v = y in the second cse. In other words, w L. This shows tht L = L (e).

3 Deterministic Finite Automt [Write your nswers on seprte pge] ) Let A = {,, c} nd let L = {w A occurs n odd numer of times s suword in w}. i) Give DFA M with L(M) = L. Explin your nswer. Define M to e, c, c q 0 q 1 q 2 c c q 3 Explntion: We hve the following invrints for the sttes. In q 0 we hve red n even numer of. In q 1 we re witing fter n, which would give us n odd numer of red. In q 2 we hve red n odd numer of In q 3 we re witing fter n, which would give us n even numer of red. The trnsitions then clerly preserve these invrints, nd since only q 2 nd q 3 re ccepting, the utomton ccepts exctly L. ii) Show tht c is ccepted, nd tht is not ccepted. (5pt) We hve q 0, c q 0, q 1, q 2, q 3, λ, thus c L(M). We hve q 0, q 1, q 2, q 2, q 3, q 0, λ, thus is not ccepted. ) Let A = {, } nd the DFA M over A e given y q 0 q 1 q 2

Use the procedure from the lecture to construct regulr expression e with L (e) = L(M). First, we need to trnsform M to only hve one finl stte: q 0 q 1 q 2 1 1 f Then we eliminte q 1 : + q 0 q 2 1 1 f Next, we eliminte q 2 : + + q 0 1 + f Thus e is given y ( + + ) (1 + ). 4 Non-Deterministic Finite Automt [Write your nswers on seprte pge] ) Let A = {0, 1, 2} nd let L e the lnguge of words in which the digits occur only in incresing order, i.e., L = {x 1 x n n N, i. x i A nd i j. x i x j }. i) Show tht L is regulr y constructing n NFA-λ tht ccepts L.

0 1 2 q λ 0 q λ 1 q 2 ii) Show tht your utomton ccepts 002 nd rejects 21. (5pt) We hve hence 002 is ccepted. We hve hence 21 is not ccepted. q 0, 002 q 0, 02 q 0, 2 q 1, 2 q 2, 2 q 2, λ, δ (q 0, 21) = q λ closure(q 0) p δ(q,2) = δ (q 2, 1) =, ) Let A = {,, c} nd the NFA-λ M over A e given y, c δ (p, 1) q 0 q 1 q 2 q 3 λ Use the procedure from the lecture to construct DFA D with L(D) = L(M). Indicte clerly from which suset of sttes of M stte in D origintes. λ {q 0, q 3 } {q 1 }, c, c {q 1, q 2 } {q 1, q 2, q 3 }, c, c c) Let e e the regulr expression + ( + 1). Use the procedure from the lecture to construct n NFA-λ M with L(M) = L (e).

Tlen en Automten Test 2, Thu 21 st Jn, 2016 This test consists of four exercises over 4 pges. Explin your pproch. You cn score mximum of 100 points, nd ech question indictes how mny points it is worth. The test is closed ook. You re NOT llowed to use clcultor, computer or moile phone. You my nswer in Dutch or in English. Plese write clerly, nd do not forget to put on ech pge: your nme nd your student numer. Nottion Throughout the test, we denote for ny lphet A nd A y w the numer of s in the word w A, s it ws introduced in the lecture. Write the nswer to ech exercise on seprte sheet! 1 Non-Regulr Lnguges Write your nswers on seprte sheet Let A = {, }. ) We define the lnguge L to e L = {w n w A, w = n}. Show tht L is not regulr. (5pt) Assume tht L is regulr nd let p > 0 e the pumping length which we get from the pumping lemm (PL). Tke w = p p L, which cn e divided y the PL into w = xyz with y 1, xy p such tht xy i z L for ll i N. By the ove constrints we immeditely get tht y = k with k > 0. Tke i = 0. So xy 0 z = p k p L. But p k p, so xy 0 z L. Contrdiction, hence L is not regulr. Students my use the following rgument L L ( ) = { n n n N}, which is not regulr. Thus L cnnot e regulr. However: L L ( ) = { m n m n}, so this rgument is incorrect. ) Show tht the lnguge L = {w A w = w } is not regulr, using the Pumping Lemm. Assume tht L is regulr nd let p > 0 e the pumping length which we get from the pumping lemm (PL). Tke w = p p L, which cn e divided y the PL into w = xyz with y 1, xy p such tht xy i z L for ll i N. By the ove constrints we immeditely get tht y = k with k > 0. Tke i = 0 (or i = 2 lso works). So xy 0 z = p k p L. But p k p, so xy 0 z L. Contrdiction, hence L is not regulr.

2 Context Free Grmmrs Write your nswers on seprte sheet Fix A = {, } for this exercise. ) Let L e the lnguge over A given y L = { n k m k = n + m}. i) Construct CFG G such tht L(G) = L. G is given y the productions S LR L L λ R R λ hving non-terminls {S, L, R} nd strt symol S. ii) Give derivtion for the word L. (5pt) S LR LR LR R R iii) Show tht the word is not generted. (5pt) The only possile wy to get the first is y S LR LR R ut then from R we cn only get to λ or to..., so we cnnot generte. Alterntive: Full Cse Explortion Strting from S, we hve the following possile derivtions. S LR {LR, LR, R, L} For these, in turn, we hve LR {R, LR, L, LR} Thus in ech cse either too little s or to mny s re produced. LR {R, LR, L, LR} Similr R cnnot produce in front of L cnnot produce in front of Thus in neither of these cses we cn derive, so it is note in the lnguge generted y the grmr.

) Let G e the following CFG over A. S US λ U i) Give precise description of L(G) using set nottion. (5pt) L(G) = {w A w even} = {w 1 w n n N, w i {,,, }} = L ( ( + + + ) ) ii) Is L(G) regulr lnguge? Explin your nswer y either giving reson why it is not or y giving regulr grmmr for L(G). L(G) is regulr. We cn sustitute U in the first production of S to otin S S S S S λ. This cn e refined into the following regulr grmmr. S A B B A λ A S B S More compct solution S T T λ T S S 3 Push Down Automt I Write your nswers on seprte sheet Let M e the PDA with Q = {q 0, q 1, q 2 } Σ = {,, c} Γ = {B, C} F = {q 0 } δ(q 0,, λ) = { q 1, B } δ(q 0,, C) = { q 1, λ } δ(q 0, c, λ) = { q 2, C } δ(q 0, c, B) = { q 2, λ } δ(q 1,, λ) = { q 0, λ } δ(q 2,, λ) = { q 0, λ } ) Drw stte digrm for M. (5pt)

M cn e drwn s, λ/b, C/λ strt q 0 q 1, λ/λ, λ/λ c, λ/c c, B/λ q 2 ) Check which of the following words is in L(M) nd explin your nswer: c nd c. (5pt) There is no trnsition from q 0 tht reds n, so c / L(M). q 0, c, λ q 1, c, B q 0, c, λ q 2,, C q 0, λ, λ. We end in n ccepting stte with n empty stck, so c L(M). c) Is L ( (c) () ) L(M)? Explin your nswer. (5pt) No, c L((c) () ), ut c L(M). To see the ltter, note tht when reding c, either B must e popped of the stck, or C is pushed on the stck. The first is not possile with n empty stck, nd fter the second the stck is not empty. Alterntively: if w L(M) then the numer of s nd s in w is equl, following the sme rgument s ove. This does not hve to e the cse for every w L((c) () ). d) Give precise description of L(M) using set nottion. (5pt) L(M) = {w L((c + c) ) w = w }. Tht is, the words with n equl numer of s nd s, where every nd every is followed y c, nd every c is preceded y n or. 4 Push Down Automt II Write your nswers on seprte sheet

) i) Let A = {, } nd let L e the lnguge L = {w A w = 2 w + 1}. Show tht L is context free y giving PDA tht ccepts it., A/λ, B/λ, λ/aa, λ/λ λ, λ/ q 0 q 1 q 2, λ/b, λ/a ii) Show tht nd re ccepted, y giving the ccepting computtions. (5pt) q 0,, λ q 1,, λ q 2,, λ q 1,, A q 1, λ, λ q 0,, λ q 0,, AA q 1,, AA q 1,, A q 1, λ, λ iii) Show tht is not ccepted y your PDA. (5pt) We hve the following possile computtions (q 0,, λ) (q 1,, ) {(q 1,, λ), (q 2,, )} {(q 2,, λ), (q 1,, )} {(q 1, λ, ), (q 1, λ, )}, neither of which ends with n empty stck. Thus is not ccepted. ) Let G e the grmmr on the lphet {, } given s follows. S λ X Y X Y Y X Construct PDA tht ccepts L(G), using the procedure given in the lecture.

First we trnsform the grmmr into the form necessry construct PDA. The resulting PDA is then. S λ X Y X Y B B Y XA A A B, λ/x, λ/y λ, λ/λ, X/Y B, X/B, A/λ, B/λ, Y/XA, Y/A