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

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

Harvard University Computer Science 121 Midterm October 23, 2012

Homework 3 Solutions

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

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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.

Chapter 2 Finite Automata

Finite-State Automata: Recap

Convert the NFA into DFA

NFAs continued, Closure Properties of Regular Languages

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

Finite Automata-cont d

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

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

NFAs continued, Closure Properties of Regular Languages

1 Nondeterministic Finite Automata

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

Non-deterministic Finite Automata

CMSC 330: Organization of Programming Languages

Formal Languages and 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.

Non-deterministic Finite Automata

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

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

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

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

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

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

Minimal DFA. minimal DFA for L starting from any other

Languages & Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata

CHAPTER 1 Regular Languages. Contents

Java II Finite Automata I

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

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.

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

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Name Ima Sample ASU ID

Theory of Computation Regular Languages

Deterministic Finite Automata

Designing finite automata II

Lecture 09: Myhill-Nerode Theorem

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

Let's start with an example:

First Midterm Examination

Midterm 1 Practice. CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

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

a,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1

Some Theory of Computation Exercises Week 1

First Midterm Examination

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

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

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

State Minimization for DFAs

Lecture 08: Feb. 08, 2019

3 Regular expressions

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Formal languages, automata, and theory of computation

1 From NFA to regular expression

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

Fundamentals of Computer Science

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers

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

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

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

Worked out examples Finite Automata

Lexical Analysis Finite Automate

Deterministic Finite-State Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

input tape head moves current state

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

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

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

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

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

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

Closure Properties of Regular Languages

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

Lecture 2e Orthogonal Complement (pages )

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

Lecture 9: LTL and Büchi Automata

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

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Bases for Vector Spaces

CSE396 Prelim I Answer Key Spring 2017

80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers

FABER Formal Languages, Automata and Models of Computation

CS S-12 Turing Machine Modifications 1. When we added a stack to NFA to get a PDA, we increased computational power

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Formal Methods in Software Engineering

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

SWEN 224 Formal Foundations of Programming WITH ANSWERS

CS 275 Automata and Formal Language Theory

Nondeterminism and Nodeterministic Automata

The size of subsequence automaton

Speech Recognition Lecture 2: Finite Automata and Finite-State Transducers. Mehryar Mohri Courant Institute and Google Research

NON-DETERMINISTIC FSA

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

Closure Properties of Regular Languages

Transcription:

CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts the empty string (i.e., ɛ), does M s strt stte hve to e n ccepting stte? Why or why not? No it does not hve to e n ccepting stte. ecuse M is n NF, we cn ccept the empty string y hving non-ccepting strt stte which hs n ɛ-trnsition (or sequence of such ɛ-trnsitions) to n ccepting stte. () Is every finite lnguge regulr? Why or why not? Yes. Every finite lnguge is regulr. You cn uild n NF for it y uilding liner DF tht recognizes ech string individully. Then join them ll to common strt stte using ɛ-trnsitions. (c) Suppose tht n NF M = (Q, Σ, δ, q, F ) ccepts lnguge L. Crete new NF M y flipping the ccept/non-ccept mrkings on M. Tht is, M = (Q, Σ, δ, q, Q F ). Does M ccept L (the set complement of L)? Why or why not? This only works for DF. Consider the following NF. It ccepts the lnguge {}. If you flip the ccept mrkings, it recognizes {, ɛ}. q q q 2 (d) Simplify the following regulr expression ( ) ɛ. This is equl to ɛ( ) which is just. This cn lso e written s + +.

Prolem 2: DF design (6 points) Let Σ = {, }. Let L e the set of strings in Σ which contin the sustring or the sustring. For exmple, L nd L, ut / L. Strings shorter thn three chrcters re never in L. Construct DF tht ccepts L nd give stte digrm showing ll sttes in the DF. You will receive zero credit if your DF uses more thn sttes or mkes significnt use of non-determinism., F Prolem 3: Rememering definitions (8 points) () Define formlly wht it mens for DF (Q, Σ, δ, q, F ) to ccept string w = w w 2... w n. The DF ccepts w if there is stte sequence s s... s n such tht s = q s n F, nd s i = δ(s i, w i ) for every i [i, n]. () Let Σ nd Γ e lphets. Suppose tht h is function from Σ to Γ. Define wht it mens for h to e homomorphism. mpping h is homomorphism if h(xy) = h(x)h(y) for ny strings x nd y. Or, equivlently, h is homomorphism if h(c c 2... c n ) = h(c )h(c 2 )... h(c n ) for ny sequence of chrcters c c 2... c n. 2

Or, you could sy it in words: the output of h on string is the conctention of its outputs on the individul chrcters mking up the string. Or you could even sy: h is homomorphism if it opertes on strings chrcter-y-chrcter. Prolem 4: NF trnsitions (6 points) Suppose tht the NF N = (Q, {,, 2}, δ, q, F ) is defined y the following stte digrm: 2 ǫ D 2 ǫ C E Fill in the following vlues: () F = F = {D}. () δ(, ) = δ(, ) = (c) δ(c, ) = δ(c, ) = {D, E} (d) δ(d, ) = δ(d, ) = {} (e) List the memers of the set {q Q D δ(q, 2)} E. (f) Does the NF ccept the word 2? (Yes / No) Yes. The stte sequence is CDCDD. 3

Prolem 5: NF to DF conversion (6 points) Convert the following NF to DF recognizing the sme lnguge, using the suset construction. Give stte digrm showing ll sttes rechle from the strt stte, with n informtive nme on ech stte. ssume the lphet is {, }., C D D CD D C, Prolem 6: Short Construction (8 points) () Give regulr expression for the lnguge L contining ll strings in whose length is multiple of three. E.g. L contins ut does not contin or. () () () () () (). 4

() Let Σ = {,, c}. Give n NF for the lnguge L contining ll strings in Σ which hve n or c in the lst four positions. E.g. nd c re oth in L, ut c is not. Notice tht strings of length four or less re in L exctly when they contin n or c. You will receive zero credit if your NF contins more thn 8 sttes.,,c,c,,c,,c,,c 2 3 4 Prolem 7: NF modifiction nd tuple nottion (8 points) For this prolem, the lphet is lwys Σ = {, }. Given n NF M tht ccepts the lnguge L, design new NF M tht ccepts the lnguge L = {twt w L, t Σ}. For exmple, if is in L, then nd re in L. () riefly explin the ide ehind your construction, using English nd/or pictures. The new NF M hs two copies of M s sttes, plus new initil nd finl sttes. Copy is for the strings strting in nd copy is for the strings strting in. When we red the first chrcter, we trnsition to the strt stte of the pproprite copy. When we rech finl stte in our copy, there is trnsition from tht finl stte to the new finl stte, consuming the pproprite input chrcter. E.g. the finl sttes of copy hve trnsition on into the new finl stte. () Suppose tht M = (Q, Σ, δ, q, F ). Give the detils of your construction of M, using tuple nottion. M = (Q, Σ, δ, q S, {q F }) where Q = {q S, q F } {q q Q} {q q Q} nd δ is defined s follows: δ (q S, ) = q δ (q S, ) = q δ (q, t) = {r r δ(q, t)} if q Q F, or if q F nd t = δ (q, t) = {r r δ(q, t)} if q Q F, or q F nd t = δ (q, ) = {q F } {r r δ(q, t)} for every q F 5

δ (q, ) = {q F } {r r δ(q, t)} for every q F δ (q, t) = for ll other inputs Notice tht the old finl sttes in ech copy of M need to keep ll their old trnsitions nd lso dd the trnsition into the new finl stte. Full credit didn t require getting solutely every detil correct. The ig mistke mny people mde ws to use single copy of the originl set of sttes, to which they just dded new strt nd end sttes to M. This doesn t llow the NF to rememer the first chrcter of the string, so it cn t verify tht the lst chrcter is the sme. Resonly well-formed versions of this nswer were worth 2/8 points. 6