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

Similar documents
CMSC 330: Organization of Programming Languages

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

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

Minimal DFA. minimal DFA for L starting from any other

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

Let's start with an example:

Convert the NFA into DFA

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

Worked out examples Finite Automata

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

Finite Automata-cont d

Lexical Analysis Finite Automate

Non-deterministic Finite Automata

Java II Finite Automata I

Nondeterminism and Nodeterministic Automata

First Midterm Examination

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

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

State Minimization for DFAs

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Deterministic Finite Automata

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

Formal Languages and Automata

Lecture 08: Feb. 08, 2019

First Midterm Examination

Designing finite automata II

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

Non-deterministic Finite Automata

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

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

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

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

CHAPTER 1 Regular Languages. Contents

CS375: Logic and Theory of Computing

FABER Formal Languages, Automata and Models of Computation

NFAs continued, Closure Properties of Regular Languages

Homework 3 Solutions

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

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

Chapter 2 Finite Automata

Myhill-Nerode Theorem

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

Finite-State Automata: Recap

Theory of Computation Regular Languages

GNFA GNFA GNFA GNFA GNFA

3 Regular expressions

Formal languages, automata, and theory of computation

Closure Properties of Regular Languages

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

Lecture 09: Myhill-Nerode Theorem

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

input tape head moves current state

CS 573 Automata Theory and Formal Languages

Formal Language and Automata Theory (CS21004)

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

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

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

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

ɛ-closure, Kleene s Theorem,

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

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.

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

Lexical Analysis Part III

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

Fundamentals of Computer Science

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS 275 Automata and Formal Language Theory

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

1 Nondeterministic Finite Automata

Chapter 1, Part 1. Regular Languages. CSC527, Chapter 1, Part 1 c 2012 Mitsunori Ogihara 1

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.

Harvard University Computer Science 121 Midterm October 23, 2012

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

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

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

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

Today s Topics Automata and Languages

Automata and Languages

Closure Properties of Regular Languages

NFAs continued, Closure Properties of Regular Languages

NON-DETERMINISTIC FSA

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

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

CS 267: Automated Verification. Lecture 8: Automata Theoretic Model Checking. Instructor: Tevfik Bultan

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

2. Lexical Analysis. Oscar Nierstrasz

CS375: Logic and Theory of Computing

CISC 4090 Theory of Computation

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

Name Ima Sample ASU ID

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

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

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

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

1 From NFA to regular expression

Thoery of Automata CS402

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

Transcription:

NFA DFA Exmple 3 CMSC 330: Orgniztion of Progrmming Lnguges NFA {B,D,E {A,E {C,D {E Finite Automt, con't. R = { {A,E, {B,D,E, {C,D, {E 2 Equivlence of DFAs nd NFAs Any string from {A to either {D or {CD represents pth from A to D in the originl NFA Equivlence of DFAs nd NFAs (cont.) Cn reduce ny NFA to DFA using suset lg. How mny sttes in the DFA? Ech DFA stte is suset of the set of NFA sttes Given NFA with n sttes, DFA my hve 2 n sttes Since set with n items my hve 2 n susets Corollry Reducing NFA with n sttes my e O(2 n ) NFA DFA 3 4

Implementing DFAs Implementing DFAs (Alterntive) It's esy to uild progrm which mimics DFA cur_stte= 0; while (1) { symol= getchr(); switch (cur_stte) { cse 0: switch (symol) { cse '0': cur_stte= 0; rek; cse '1': cur_stte= 1; rek; cse '\n': printf("rejected\n"); return 0; defult: printf("rejected\n"); return 0; rek; cse 1: switch (symol) { cse '0': cur_stte= 0; rek; cse '1': cur_stte= 1; rek; cse '\n': printf("ccepted\n"); return 1; defult: printf("rejected\n"); return 0; rek; defult: printf("unknown stte; I'm confused\n"); rek; Alterntively, use generic tle-driven DFA given components (Σ, Q, q 0, F, δ) of DFA: q := q 0 while (there exists nother symol s of the input string) q := δ(q, s) if q F then ccept else reject q is just n integer represent δ using rrys or hsh tles represent F s set CMSC 330 5 CMSC 330 6 Run Time of Algorithm Regulr Expressions in Prctice Given string s, how long does lgorithm tke to decide whether s is ccepted? ssume we cn compute δ(q0, c) in constnt time then the time per string s to determine cceptnce is O( s ) cn t get much fster! But recll tht constructing the DFA from the NFA constructed from the regulr expression A my tke O(2 A ) time ut this is usully not the cse in prctice So there s the initil overhed, ut then ccepting strings is fst CMSC 330 7 Regulr expressions re typiclly compiled into tles for the generic lgorithm cn think of this s simple yte code interpreter ut relly just representtion of (Σ, Q A, q A, {f A, δ A ), the components of the DFA produced from the r.e. Regulr expression implementtions often hve extr constructs tht re non-regulr i.e., cn ccept more thn the regulr lnguges cn e useful in certin cses disdvntges: nonstndrd, plus cn hve higher complexity CMSC 330 8

Minimizing DFA Result from CS theory Every regulr lnguge is recognizle y minimum-stte DFA tht is unique up to stte nmes In other words For every DFA, there is unique DFA with minimum numer of sttes tht ccepts the sme lnguge Two minimum-stte DFAs hve sme underlying shpe S1 S2 S3 c S1 c S3 S2 9 Minimizing DFA: Hopcroft Reduction Intuition Look for sttes tht cn e distinguish from ech other End up in different ccept / non-ccept stte with identicl input Algorithm Construct initil prtition Accepting nd non-ccepting sttes Itertively refine prtitions (until prtitions remin fixed) Split prtition if memers in prtition hve trnsitions to different prtitions for sme input Two sttes x, y elong in sme prtition if nd only if for ll symols in Σ they trnsition to the sme prtition Updte trnsitions nd remove ded sttes J. Hopcroft, An n log n lgorithm for minimizing sttes in finite utomton, 1971 10 Splitting Prtitions No need to split prtition {S,T,U,V All trnsitions on led to identicl prtition Even though trnsitions on led to different sttes Splitting Prtitions (cont.) Need to split prtition {S,T,U into {S,T, {U Trnsitions on from S,T led to prtition Trnsition on from U led to prtition P3 S U V T X Z Y P4 S U T X Z Y P3 11 12

Resplitting Prtitions Need to reexmine prtitions fter splits Initilly no need to split prtition {S,T,U After splitting prtition {X,Y into {X, {Y need to split prtition {S,T,U into {S,T, {U P4 S U T P3 X Y 13 DFA Minimiztion Algorithm (1) Input DFA (Σ, Q, q 0, F n, δ n ), output DFA (Σ, R, r 0, F d, δ d ) Algorithm Let p 0 = F n, p 1 = Q F // initil prtitions = finl, nonfinl sttes Let R = { p p {p 0, p 1 nd p!= Ø, P = Ø // dd p to R if nonempty While P!= R do itertion Let P = R, R = Ø prtitions For ech p P previous itertion // while prtitions chnged on prev // P = prev prtitions, R = current // for ech prtition from 14 DFA Minimiztion Algorithm (2) Algorithm for split(p,p) Choose some r p, let q = p {r, m = { // pick some stte r in p For ech s q For ech c Σ // for ech stte in p except for r // for ech symol in lphet If δ d (r,c) = q 0 nd δ d (s, c) = q 1 nd // q s = sttes reched for c Return p m, m differently thn r there is no p 1 P such tht q 0 p 1 nd q 1 p 1 then m = m {s // dd s to m if q s not in sme prtition // m = sttes tht ehve 15 Minimizing DFA: Exmple 1 Initil prtitions Accept Reject S T R Split prtition? Not required, minimiztion done move(s, ) = T move(s, ) move(t, ) = T move(t, ) { R { S, T After clenup = R = R 16

Minimizing DFA: Exmple 2 Minimizing DFA: Exmple 3 S T R S T R Initil prtitions Accept Reject { R { S, T Split prtition? Not required, minimiztion done move(s, ) = T move(s, ) = R move(t, ) = S move (T, ) = R After clenup 17 Initil prtitions Accept Reject Split prtition? Yes, different prtitions for move(s, ) = T move(s, ) move(t, ) = T move(t, ) { R { S, T P3 DFA lredy miniml = T = R 18 Complement of DFA Given DFA ccepting lnguge L, how cn we crete DFA ccepting its complement? Exmple DFA Σ = {, Complement of DFA (cont.) Algorithm: Add explicit trnsitions to ded stte Chnge every finl stte to nonfinl stte nd every nonfinl stte to finl stte Note this only works with DFAs Why not with NFAs? 19 20

Prctice Mke the DFA which ccepts the complement of the lnguge ccepted y the DFA elow. Reducing DFAs to REs Generl ide Remove sttes one y one, leling trnsitions with regulr expressions When two sttes re left (strt nd finl), the trnsition lel is the regulr expression for the DFA S3 21 22 Relting REs to DFAs nd NFAs Why do we wnt to convert etween these? Cn mke it esier to express ides Cn e esier to implement 23