Convert the NFA into DFA

Similar documents
Minimal DFA. minimal DFA for L starting from any other

1 Nondeterministic Finite Automata

Designing finite automata II

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

CMSC 330: Organization of Programming Languages

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Lexical Analysis Finite Automate

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

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

Finite Automata-cont d

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

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

Formal languages, automata, and theory of computation

Formal Languages and Automata

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

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

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.

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.

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

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

First Midterm Examination

Nondeterminism and Nodeterministic Automata

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

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

Java II Finite Automata I

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

Homework 3 Solutions

CISC 4090 Theory of Computation

Closure Properties of Regular Languages

CHAPTER 1 Regular Languages. Contents

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

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

Bases for Vector Spaces

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

First Midterm Examination

Let's start with an example:

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

Lexical Analysis Part III

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

Lecture 08: Feb. 08, 2019

3 Regular expressions

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

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

Chapter 2 Finite Automata

Thoery of Automata CS402

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

Closure Properties of Regular Languages

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

NFAs continued, Closure Properties of Regular Languages

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

State Minimization for DFAs

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

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

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

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

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

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

CS 275 Automata and Formal Language Theory

NFAs continued, Closure Properties of Regular Languages

Non-deterministic Finite Automata

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

This lecture covers Chapter 8 of HMU: Properties of CFLs

Theory of Computation Regular Languages

Lecture 09: Myhill-Nerode Theorem

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.

Myhill-Nerode Theorem

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

Model Reduction of Finite State Machines by Contraction

Normal Forms for Context-free Grammars

Worked out examples Finite Automata

Some Theory of Computation Exercises Week 1

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

Deterministic Finite Automata

Languages & Automata

1 From NFA to regular expression

CSC 473 Automata, Grammars & Languages 11/9/10

Name Ima Sample ASU ID

Non-deterministic Finite Automata

Free groups, Lecture 2, part 1

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

In-depth introduction to main models, concepts of theory of computation:

SWEN 224 Formal Foundations of Programming WITH ANSWERS

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

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

The size of subsequence automaton

Chapter 7. Kleene s Theorem. 7.1 Kleene s Theorem. The following theorem is the most important and fundamental result in the theory of FA s:

FABER Formal Languages, Automata and Models of Computation

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

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

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

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

GNFA GNFA GNFA GNFA GNFA

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

Section: Other Models of Turing Machines. Definition: Two automata are equivalent if they accept the same language.

Parse trees, ambiguity, and Chomsky normal form

1.4 Nonregular Languages

p-adic Egyptian Fractions

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

Transcription:

Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm: Constructing deterministic finite utomton from nondeterministic one. Input: n NF N. Output: F ccepting the sme lnguge. Method: Ech stte of is set of sttes which N could e in fter reding some sequence of input symols. Thus is le to simulte ll possile moves N cn mke on given input string. The initil stte of is the set consisting of S0, the initil stte of N, together with ll sttes of N tht cn e reched from S0 y mens of -trnsition only. The ccepting sttes of re those sets of sttes tht contin t lest one ccepting sttes of N. Let us define the function -CLOSURE (s) to e the set of sttes of N uilt y pplying the following rules:- 1- S is dded to -CLOSURE (s). 2- If t is in -CLOSURE (s), nd there is n edge leled from t to u, then u is dded to -CLOSURE (s) if u is not lredy there. Rule 2 is repeted until no more sttes cn e dded to -CLOSURE (s). Thus, -CLOSURE (s) is just the set of sttes tht cn e reched from S on - trnsition lone. If T is set of sttes, then -CLOSURE (T) is just the union over ll sttes S in T of -CLOSURE (S). The computtion of -CLOSURE (T) is typicl process of serching grph for nodes rechle from given set of nodes. In this cse the nodes of T re the given set, nd the grph consists of the - leled edge of the trnsition digrm only. simple lgorithm to compute -CLOSURE (T) is shown in Fig.14 31

egin Push ll sttes in T onto STCK; -CLOSURE (T):=T; While STCK not empty do Pop S, the top element of STCK, off of stck; For ech stte t with n edge from S to t leled do End End If t is not in -CLOSURE (T) then egin End dd t to -CLOSURE (T); Push t onto STCK; Fig.14: Computtion of -CLOSURE The sttes of nd their trnsition re constructed s follows. Initilly, let - CLOSURE (S0) e stte of. This stte is the strt stte of. We ssume ech stte of is initilly "unmrked". Then perform the lgorithm of Fig.15. While there is n unmrked stte x= (S1, S2... S n ) of do egin Mrk x; For ech input symol do egin Let T e the set of sttes to which there is trnsition on '' from some stte Si in x; End y: = -CLOSURE (T); If y hs not yet een dded to the set of sttes of then Mke y n "unmrked" stte of ; dd trnsition from x to y leled if not lredy present End Fig.15: The Suset Construction 32

Exmple Convert the NF shown in Fig.16 into F 0 1 6 7 8 9 10 2 4 3 5 Fig.16: NF N for ()*. Fig.16 shows NF N ccepting the lnguge ()*. The initil stte of the equivlent F is -CLOSURE (0), which is = {0, 1, 2, 4, 7}, since these re exctly the sttes rechle from stte 0 vi pth in which every edge is leled. Note tht 0 is reched from itself y such pth, the pth hving no edges. The lgorithm of Fig.15 tell us to set x to nd compute T, the set of sttes of N hving trnsitions on from memers of. mong the sttes 0, 1, 2, 4 nd 7, only 2 nd 7 hve such trnsition, to 3 nd 8, so y= -CLOSURE ({3, 8}) = {1, 2, 3, 4, 6, 7, 8} Let us cll this set. mong the sttes in, only 4 hs trnsition on to 5, so the F hs trnsition on from to C= -CLOSURE ({5}) = {1, 2, 4, 5, 6, 7} Then we hve two trnsitions:- C We continue this lgorithm for stte nd C. 33

1- For set - If the input is symol "", then only stte 2 nd 7 give trnsition on symol "" to stte 3 nd 8, therefore -CLOSURE({3,8})=, then we hve this trnsition - If the input is symol "", then only stte 4 nd 8 give trnsition on symol "" to stte 5 nd 9, therefore -CLOSURE ({5, 9}) = {1, 2, 4, 5, 6, 7, 9} Let us cll this set. ecuse stte not dded to the stte of F, then we dd it, with trnsition:- 2- For set C - If the input symol is "", then only stte 2 nd 7 hve trnsition on "" to stte 3 nd 8, therefore -CLOSURE ({3, 8}) =, then the trnsition is: C - If the input symol is "", then only stte 4 gives trnsition on to stte 5, therefore -CLOSURE (5) =C, then the trnsition is:- C C 3- For set :- - If the input symol is "", then only stte 2 nd 7 gives trnsition on "" to stte 3 nd 8, therefore -CLOSURE ({3, 8}) =, then the trnsition is - If the input symol is "" then only stte 4 nd 9 gives trnsition on "" to stte 5, nd 10, therefore:- -CLOSURE ({5, 10}) = {1, 2, 4, 5, 6, 7, 10} Let us cll this E, then the trnsition:- 4- For set E E 34

- If the input symol is "", then only stte 2 nd 7 given trnsition on "" to stte 3 nd 8, therefore:- -CLOSURE ({3, 8}) =, then the trnsition is E - If the input symol is "", then only stte 4 gives trnsition on "" to stte 5, therefore -CLOSURE (5) =C, then the trnsition is:- E C The trnsition tle for NF is shown in Fig.17, nd the F equivlent to NF of Fig.16 is shown in Fig.18. The finl stte is E ecuse it contin the stte 10 which is the finl stte for NF in Fig.16. (Strt) (ccept) Stte Input C C C E E C Fig.17: Trnsition Tle Strt C E Fig.18: F ccepting ()*. 35

Minimizing the Numer of sttes of F The F of Fig (18) constructed from the NF of Fig (16) is not the smllest possile. In prticulr, we show Fig (12), nother F with only four sttes tht lso ccept ()*. Prt of the reson for this nonminimlity of the suset construction lies in the fct tht we did not include in the lgorithm, for converting NF to F, some ovious stte identifictions tht could e mde. There re two methods for minimizing the numer of sttes nd trnsitions:- 1-Empiricl Method: This method minimized the numer of sttes nd trnsitions ccording to the following steps:- - We merge two sttes in F in one stte if they hve the sme importnt sttes. The importnt stte is the stte with no -trnsition - We merge two sttes if they either oth include or oth exclude ccepting sttes of the NF. Exmple: Minimize the F shown in Fig.19 ccording to the Empiricl method. Strt C Fig.19: F ccepting ()* = {0}, = {1, 2, 8, 3, 5}, C= {4, 7, 8, 2, 3, 5}, = {6, 7, 8, 2, 3, 5} Finl is stte 8. From Fig.19 we know tht the lnguge tht NF re shown in Fig.20 36

0 Letter 1 2 Letter 3 4 igit 5 6 7 8 Fig.20: NF ccepting ()* The importnt sttes in Fig.20 re {0, 3, 5}. We see tht stte nd C contin the sme importnt nd contin the finl stte (8), therefore we cn merge these two sttes into one stte nmed C, nd then the result is C C= {1, 2, 3, 4, 5, 6, 7, 8} fter tht we look to the stte C nd stte nd see tht they hve the sme importnt stte nd the sme finl stte, therefore we cn merge these sttes into nother stte clled C then the minimized F is shown in Fig.21. C Fig.21: NF ccepting ()* 37

2- Forml Method In this method we don t need to experience for deciding which of the stte tht re legl for merging, insted of stte we must use the following lgorithm:- lgorithm: - Minimizing the numer of sttes of F Input: - F M with set of sttes S, inputs, trnsitions defined for ll sttes nd inputs, initil stte S0, nd set the finl stte F. Output: - F M ' ccepting the sme lnguge s M nd hving s few sttes s possile. Method:- 1- We construct prtition T of the set of sttes Initilly, T consist of two groups, the finl sttes F, nd the non finl sttes S-F. Then we construct new prtition Tnew y the procedure of Fig (22). Tnew will lwys e refinement of T, mening tht Tnew consists of the groups of T, ech split into one or more pieces. If Tnew = T, then no more chnges cn ever occur, so we terminte this prt of the lgorithm: For ech group G of T do egin Prtitions G into sugroups such tht two sttes S nd t of G re in the sme sugroup iff for ll input symol, sttes S nd t hve trnsitions on to sttes in the sme group of T; End. Plce ll sugroups so formed in Tnew; Fig (22). New prtition Tnew 2- When the finl prtition T hs een constructed in step (1), select representtive for ech group, tht is, n ritrry stte in the group. The representtive will e the sttes of the reduced F M '. Let S e representtive stte, nd suppose on input there is trnsition of M from s to t. Let r e the representtive of t's group (r my e t). Then M ' hs trnsition from S to r on. Let the initil stte of M ' e the representtive of the group contining the initil S0 38

of M, nd let the finl sttes of M ' e the representtive which re in F. Note tht ech group of T either consists only of sttes in F or hs no sttes in F. 3- If M ' hs ded stte, tht is, stte d which is not finl nd with trnsitions to itself on ll input symol, then remove d from M '. lso remove ny stts not rechle from the initil stte. ny trnsitions to d from other sttes ecome undefined. Exmple:- Minimize The F shown in Fig.18 Solution: The initil prtition of T consists of two groups: 1- The finl sttes:- which contins (E) 2- The non finl sttes:- which contins (C). To construct Tnew y the lgorithm of Fig (22), (1) We first consider (E), since this consists of one stte, it cnnot e further split, so we plce (E) in Tnew. (2) Now consider (C) nd do the following:- () If the input is, then ech of these sttes goes to, so they could ll e plced in one group s fr s input is consumed. () If the input is, then,, nd C go to memers of the group (C) of T, while goes to E, memer of nother group. Thus, in Tnew (C) must e split into groups (C) nd (). The new vlue of T is thus (C)() (E). Constructing the next Tnew, we given hve no splitting on input, ut (C) must e split into two groups (C) (), since on input nd C ech go to C, while goes to, memer of group of T different from tht of C. Thus the next vlue of T is (C) () () (E). When we construct Tnew from this, we cnnot split ny of the groups consisting of single stte. The only possiility is tht (C) could e split. ut nd C go to the sme stte,, on input, nd they go to the sme stte, C, on input. Hence, Tnew=T, nd the finl prtition T from step (1) of lgorithm is (C) () () (E). 39

Let us now choose representtives. Of course, nd E represent the group contining only themselves. Let us choose to represent the group (C). Then the trnsition tle for the reduce utomton is shown in Fig.23. (Strt) (ccept) Stte Input E E Fig.23: Reduced utomton For exmple, E goes to C on input in the utomt of Fig.18. Since is the representtive of the group for C, we hve trnsition from E to on input in Fig.23. similr chnge hs tken plce in entry for on input, nd ll other trnsitions re copied from Fig.18. There is no ded stte in Fig.23, nd ll sttes re rechle from the initil stte. Fig.24 shows the minimized F. Strt E Fig.24: Minimized F ccepting ()*. 40