Designing finite automata II

Similar documents
1 Nondeterministic Finite Automata

Convert the NFA into DFA

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

Minimal DFA. minimal DFA for L starting from any other

Formal Languages and Automata

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Nondeterminism and Nodeterministic Automata

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

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

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

1 From NFA to regular expression

Some Theory of Computation Exercises Week 1

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

3 Regular expressions

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

Let's start with an example:

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

Fundamentals of Computer Science

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.

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

Java II Finite Automata I

Chapter 2 Finite Automata

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

Theory of Computation Regular Languages

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

CMSC 330: Organization of Programming 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.

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

Homework 3 Solutions

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

Worked out examples Finite Automata

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

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

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

CHAPTER 1 Regular Languages. Contents

CISC 4090 Theory of Computation

Formal languages, automata, and theory of computation

Deterministic Finite Automata

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

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

Non-Deterministic Finite Automata

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

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

DFA minimisation using the Myhill-Nerode theorem

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

Thoery of Automata CS402

Formal Language and Automata Theory (CS21004)

Lecture 08: Feb. 08, 2019

Lexical Analysis Finite Automate

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

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

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

Finite Automata-cont d

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

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

GNFA GNFA GNFA GNFA GNFA

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

NFAs continued, Closure Properties of Regular Languages

Finite-State Automata: Recap

First Midterm Examination

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

Model Reduction of Finite State Machines by Contraction

First Midterm Examination

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

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

Normal Forms for Context-free Grammars

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

State Minimization for DFAs

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

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

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

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

Lecture 09: Myhill-Nerode Theorem

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

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

Tutorial Automata and formal Languages

Context-Free Grammars and Languages

Languages & Automata

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

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

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

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

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

SWEN 224 Formal Foundations of Programming WITH ANSWERS

CS 275 Automata and Formal Language Theory

Lecture 9: LTL and Büchi Automata

NFAs continued, Closure Properties of Regular Languages

Name Ima Sample ASU ID

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

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

Coalgebra, Lecture 15: Equations for Deterministic Automata

Non-deterministic Finite Automata

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

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

Closure Properties of Regular Languages

1.3 Regular Expressions

Nondeterministic Automata vs Deterministic Automata

Transcription:

Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of the possiilities: q 3n, q 3n+1, q 3n+2 (2) Add the trnsitions telling how the possiilities rerrnge, select the initil stte nd the fvourle sttes (3) Test the utomton > q 3n q 3n+1 q 3n+2 Fundmentls of Computing (5) 1

Pttern mtching Prolem: Design DFA A such tht L(A) consists of ll strings of s nd s which contin s sustring There re four possiilities to rememer: hven t seen ny symols of the pttern: (initil) stte s hve just seen n : stte q hve just seen : stte q or hve just seen the entire pttern : (fvourle) stte q > s q q q Fundmentls of Computing (5) 2

DFA s theoreticl model for progrmming unusul, different from conventionl progrmming lnguges mjor concepts of impertive progrmming (eg, sequences, rnching, loops) cn e simulted elegnt, simple to use, hs thoroughly developed theory ll pttern mtching (eg, WWW serch engines) cn e descried limited expressive power (the utomton is not cple of incresing ny of its resources during computtion) Wht out suprogrm clls? Fundmentls of Computing (5) 3

Comining two utomt Prolem: Design n utomton tht ccepts ll the strings tht hve either two consecutive s or two consecutive s On pge 24 (4), there is DFA A 4 ccepting ll the strings tht hve two consecutive s This utomton cn esily e trnsformed into n utomton A 4 tht ccepts ll the strings with two consecutive s Since we lredy hve progrms tht solve the prolem for s nd, respectively, s, n ovious ide would e to design progrm tht would just cll the given progrms s suprogrms A possile solution would e to comine the initil sttes of A 4 nd A 4 Fundmentls of Computing (5) 4

Comining two utomt (cont) Given: L(A 4 ) = ll words hving two consecutive s L(A 4 ) = ll words hving two consecutive s Need: n utomton A such tht L(A) = L(A 4 ) L(A 4 ) q 2 r 2 > s q 1 r 1 Fundmentls of Computing (5) 5

Nondeterminism Oserve tht the stte trnsition digrm on the previous slide no longer represents DFA: there is more thn one rrow coming out of the initil stte s with identicl lels (sy, ) We sy tht this utomton is nondeterministic ecuse, eing in stte s nd reding from the input tpe, the device now hs choice: it cn choose to move either to stte q 1 or to stte s Wht cn ffect this choice? We my imgine tht the utomton just tries to guess which wy will led it finlly to fvourle stte Fundmentls of Computing (5) 6

But rel computers cnnot guess This rgument cn hrdly e refuted However, one cn justify this vrint of finite utomt y the following: Nondeterministic finite utomt re much esier to design thn deterministic ones They llow us to model how progrms re uilt from suprogrms Whtever cn e done y nondeterministic finite utomton cn lso e done (though usully in it more complicted wy) y deterministic one In other words, nondeterminism does not increse the computtionl power of finite utomt Fundmentls of Computing (5) 7

More nondeterminism There re other fetures of nondeterministic finite utomt (NFA): Just s from some sttes with some input symols there my e severl different possile next sttes, so with other comintions of sttes nd input symols there my e no possile moves t ll (like in the exmple elow, there is no -rrow coming out of s) We lso llow the mchine to jump from stte to nother stte without consuming ny input symol These jumps will e indicted on the stte trnsition digrms y rrows lelled with the empty word ε (Trnsition tles re no longer dequte to descrie these utomt) > s q r ε Fundmentls of Computing (5) 8

Acceptnce of words y NFAs A word w is ccepted y n NFA A if there exists computtion of A on input w ending up with configurtion (q, ε), for some fvourle stte q Otherwise, A rejects the input word So n NFA cn reject n input word ecuse every computtion on this input is either stuck or ends up with configurtion (q, ε), ut q is not fvourle stte There cn e more thn one computtion on n input word!! Fundmentls of Computing (5) 9

Exmple: how n NFA works > s q r ε Computtions on input : (s, ), (q, ) (s, ), (r, ), (r, ), (q, ), (s, ε) stuck ccepted Computtions on input : (s, ), (q, ), (s, ), (q, ), (s, ε) ccepted Computtions on input : (s, ), (q, ) (s, ), (r, ), (r, ), (q, ) stuck stuck (s, ), (r, ), (q, ) stuck, no more rejected Fundmentls of Computing (5) 10

0 NFA: nother exmple > s 1 q 1 p 0 0 ε Computtions on input 11: (s, 11), (q, 1) stuck (s, 11), (p, 11), (q, 1) stuck, no more rejected Computtions on input 00: (s, 00), (s, 0), (s, ε); (s, 00), (s, 0), (p, ε) stuck (s, 00), (s, 0), (p, 0); (s, 00), (p, 0) stuck (s, 00), (p, 00) stuck, no more rejected Computtions on input 001: (s, 001), (s, 01), (s, 1), (q, ε) ccepted Fundmentls of Computing (5) 11

Nondeterministic Finite Automton (NFA) Forml definition: A nondeterministic finite utomton (NFA) is quintuple A = (Q, Σ,, s, F ) where Q is finite set of sttes Σ is finite set, the input lphet s Q is the initil stte F Q is the set of fvourle (or ccepting) sttes Q (Σ {ε}) Q is ternry reltion, the trnsition reltion (If A, eing in stte q Q, hs red the symol Σ, it enters one of the sttes q for which (q,, q ) is in For ny stte q such tht (q, ε, q ) is in, A cn jump from stte q to stte q without reding ny input symol) Fundmentls of Computing (5) 12

Configurtions of NFAs Let A = (Q, Σ,, s, F ) e n NFA A configurtion of A is ny pir of the form ( stte in Q, word over Σ ) Configurtion (q, w) yields configurtion (q, w ) in one step if either w = σw for some σ in Σ nd the triple (q, σ, q ) is in or w = w nd the triple (q, ε, q ) is in ( jump ) Oserve tht in generl configurtion cn yield severl (or no) configurtions in one step In other words, configurtion does not determine uniquely the configurtion it yields in one step Tht is why the utomton A is clled nondeterministic Fundmentls of Computing (5) 13

Computtions of NFAs A computtion of A on input word w is ny sequence of configurtions such tht (q 1, w 1 ), (q 2, w 2 ),, (q k, w k ) (q 1, w 1 ) = (s, w) where s is the initil stte of A every (q i, w i ) yields (q i+1, w i+1 ) in one step, nd either w k is the empty word ε, or the configurtion (q k, w k ) yields no configurtion in one step (it gets stuck) There cn e more thn one computtion on n input word Fundmentls of Computing (5) 14

NFAs nd prllelism Nondeterminism cn e viewed s kind of prllel computtion wherein severl processes cn e running concurrently Suppose we re running n NFA on n input string nd come to stte nd red symol with multiple wys to proceed Then the mchine splits into multiple copies of itself nd follows ll the possiilities in prllel If there re susequent choices, the mchine splits gin If the next input symol does not pper on ny rrows exiting the stte occupied y copy of the mchine, tht copy dies, the rnch of computtion ssocited to it is stuck If stte with some exiting ε-rrows is encountered then, without reding ny input, the mchine splits into multiple copies: one following ech exiting ε-rrow, nd one stying t the current stte Fundmentls of Computing (5) 15

Differences etween NFAs nd DFAs > s q r ε There cn e more thn one rrow lelled y the sme symol coming out of stte (eg, there re two -rrows out of r) There cn e no rrow lelled y some symol coming out of stte (eg, there is no -rrow out of q) There cn e rrows lelled y not symols from the input lphet ut y the empty word ε These rrows represent jumps (eg there is jump from s to q) Every DFA is n NFA s well! Fundmentls of Computing (5) 16

Pttern mtching revisited Prolem: Design finite utomton A such tht L(A) consists of ll strings of s nd s which contin s sustring > It is much esier to design n NFA thn DFA We will show now tht every NFA cn e converted to DFA ccepting precisely the sme words Fundmentls of Computing (5) 17

Equivlence of DFAs nd NFAs Two utomt A nd A re sid to e equivlent if they ccept the sme lnguge Clim: For every NFA A, there is DFA A equivlent to A Moreover, there is mechnicl method, n lgorithm, tht crries out this conversion from nondeterministic utomton to its deterministic equivlent Fundmentls of Computing (5) 18

Tsk: given n NFA The Suset Construction > s q r ε construct n equivlent DFA (deterministic!) wtch out: in DFA no choice, no getting stuck, no ε-jumps re llowed Things to define: new sttes? new initil stte? new fvourle sttes? new trnsitions (rrows)? Fundmentls of Computing (5) 19

Suset construction: the new sttes NFA: > s q r ε The new sttes: ll the susets of the NFA s sttes ( stte of DFA represents ll the sttes of NFA tht cn e reched from the initil stte on the input consumed so fr) The new initil stte: the set contining the NFA s initil stte plus ll those sttes tht re rechle from it y some ε-jumps The new fvourle sttes: those susets tht contin t lest one of the NFA s fvourle sttes {s} {r} {s, r} {q} {s, q} {q, r} {s, q, r} Fundmentls of Computing (5) 20

Suset construction: the new trnsition function Recll: Being in stte nd reding n input symol, the trnsition function gives the utomton s next stte And the new sttes re susets of the old sttes now Generl rule: P? the set of ll those sttes tht re rechle from some stte in the set P either y n -rrow, or y n -rrow followed y possily one or more ε-jumps Fundmentls of Computing (5) 21

NFA: Exmple: computing the new trnsition function > s q r ε DFA: -rrow leving stte {s, q, r} goes to {s, q, r} -rrow leving stte {s, q, r} goes to {q, r} s s q ε q r r s q q r r Fundmentls of Computing (5) 22

Suset construction: the new trnsition function NFA: > s q r ε DFA: {s} {r} {s, r} {q} {s, q} {q, r} {s, q, r} Fundmentls of Computing (5) 23

Removing the unrechle sttes Oserve tht there is no computtion going through the sttes {s} nd {s, r}, so we cn sfely remove them together with their outgoing rrows: {r} {q} {s, q} {q, r} {s, q, r} The initil stte is never removle! (ll computtions strt there) Fundmentls of Computing (5) 24

Stte minimistion prolem We sw tht it is very esy to design nondeterministic finite utomt for, sy, pttern mtching prolems However, n NFA cnnot e directly implemented s computer progrm One must convert it into DFA But the numer of sttes of the resulting DFA my increse significntly 2 numer of sttes of the originl NFA in the worst cse An importnt field where finite utomt re eing used is hrdwre design: some components of hrdwre re sed on simultion of DFA An importnt ojective here is to use finite utomt tht hve minimum possile numer of sttes There re methods for doing this (The suset construction is just the initil phse of design) Fundmentls of Computing (5) 25