SlideShare a Scribd company logo
1 of 5
Example 2.16: consider the NFA of Figure 2.8




M                     ε-closure of M (S)       S′a   S′b
1                   1,2,6                      3,7
3,7                 3,4,7,8                          5
5                   5,8

                             a                   b




                                        1
Example 2.17: consider the NFA of Figure 2.9 (regular expression letter(letter|digit)*)




    M                    ε-closure of M (S)      S′letter           S′digit
    1                 1                          2
    2                 2,3,4,5,7,10               6                  8
    6                 4,5,6,7,9,10               6                  8
    8                 4,5,7,8,9,10               6                  8



                                                                                  le tte r




                                            2
2.4.3 Simulating an NFA using the subset construction

      As mentioned at section 2.3.
      NFAs can be implemented in similar ways to DFAs, except that since NFAs are
nondeterministic, there are potentially many different sequences of transitions that
must be tried.
      A program that simulates an NFA must store up transitions that have not yet been
tried and backtrack to them on failure.

    An other way of simulating an NFA is to use the subset construction, but instead
of constructing all the states of the associated DFA, we construct only the state at each
point that is indicated by the next input character.

    The advantage: we may not need to construct the entire DFA.

             In example 2.16, the input string consisting of the single character a.
                               a                           b




    The disadvantage: a state may be constructed many times, if the path contains loops.
           In example 2.17, given the input string r2d3




2.4.4 Minimizing the number of states in a DFA
    The process we have described of deriving a DFA algorithmically from a regular
expression has the unfortunate property that the resulting DFA may be more complex
than necessary.

    For example 2.15 we derived the DFA for the regular expression a*:




whereas the DFA will do as well.

                                                       a




                                                3
An important result from automata theory states that,
     given any DFA, there is an equivalent DFA containing a minimum number of
states,
     and, that this minimum-state DFA is unique (except for renaming of states).

 It is also possible to directly obtain this minimum-state DFA from any given DFA.

  Given the algorithm as follow:
   (1) It begins with the most optimistic assumption possible.
        It creates two sets, one consisting of all the accepting states and the other
   consisting of all the non-accepting states.

   (2) Given this partition of the states of the original DFA, consider the transitions on
      each character a of the alphabet.
        If all accepting states have transitions on a to accepting states, then this
           defines an a-transition from the new accepting state (the set of all the old
           accepting states) to itself.
        If all accepting states have transitions on a to non-accepting states, then this
           defines an a-transition from the new accepting state to the new non-
           accepting state (the set of all the old non-accepting stales).
        On the other hand, if there are two accepting states s and t that have
           transitions on a that land in different sets, then no a-transition can be
           defined for this grouping of the states. We say that a distinguishes the states
           s and t
        We must also consider error transitions to an error state that is non-
           accepting. If there are accepting states s and t such that s has an a-transition
           to another accepting state, while t has no a-transition at all (i.e., an error
           transition), then a distinguishes s and t.

   (3) If any further sets are split, we must return and repeat the process from the
       beginning. This process continues until either all sets contain only one element
       (in which case, we have shown the original DFA to be minimal) or until no
       further splitting of sets occurs.




                                           4
le tte r




Example 2.18: The regular expression letter(letter|digit)*




      The accepting sets                {2,3,4,5,7,10},{4,5,6,7,9,10},{4,5,7,8,9,10}
      The nonaccepting sets             {1}
 The following minimum-state DFA :
                                                              letter




                                                              digit



    Example 2.19: the regular expression (a| ε)b*




    The accepting sets                         {1,2,3}
    The non-accepting sets

     state 1 has an a-transition to an accepting state, while states 2 .and 3 have no
a-transition (or, rather, an error transition on a to the error nonaccepting state).
     Thus, a distinguishes state 1 from states 2 and 3,
     and we must repartition the states into the sets {1} and {2,3}.
     Now we begin over. The set {1} cannot be split further, so we no longer consider it.
Now the states 2 and 3 cannot be distinguished by either a or b.




                                           5

More Related Content

What's hot

HOMOGENEOUS LINEAR PDE
HOMOGENEOUS LINEAR PDEHOMOGENEOUS LINEAR PDE
HOMOGENEOUS LINEAR PDE
KomathiJ
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
ijceronline
 

What's hot (12)

HOMOGENEOUS LINEAR PDE
HOMOGENEOUS LINEAR PDEHOMOGENEOUS LINEAR PDE
HOMOGENEOUS LINEAR PDE
 
Functional dependency
Functional dependencyFunctional dependency
Functional dependency
 
14 pro resolution
14 pro resolution14 pro resolution
14 pro resolution
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfa
 
05 dataflow
05 dataflow05 dataflow
05 dataflow
 
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...IJCER (www.ijceronline.com) International Journal of computational Engineerin...
IJCER (www.ijceronline.com) International Journal of computational Engineerin...
 
Design of a Pseudo-Random Binary Code Generator via a Developed Simulation Model
Design of a Pseudo-Random Binary Code Generator via a Developed Simulation ModelDesign of a Pseudo-Random Binary Code Generator via a Developed Simulation Model
Design of a Pseudo-Random Binary Code Generator via a Developed Simulation Model
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
NFA DFA Equivalence theorem
NFA DFA Equivalence theorem NFA DFA Equivalence theorem
NFA DFA Equivalence theorem
 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
 
Lec39
Lec39Lec39
Lec39
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 

Viewers also liked (8)

Ch8a
Ch8aCh8a
Ch8a
 
Ch8b
Ch8bCh8b
Ch8b
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Chapter Eight(1)
Chapter Eight(1)Chapter Eight(1)
Chapter Eight(1)
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Three address code In Compiler Design
Three address code In Compiler DesignThree address code In Compiler Design
Three address code In Compiler Design
 
Code generation
Code generationCode generation
Code generation
 

Similar to Chapter 2 2 1 2

Chapter 2 2 1 1
Chapter 2 2 1 1Chapter 2 2 1 1
Chapter 2 2 1 1
bolovv
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
venkatapranaykumarGa
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
raosir123
 
Comparative Report Ed098
Comparative Report Ed098Comparative Report Ed098
Comparative Report Ed098
mikebrowl
 

Similar to Chapter 2 2 1 2 (17)

CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
CS 162 Fall 2015 Homework 1 Problems September 29, 2015 Timothy Johnson 1. Ex...
 
Hwsoln03 toc
Hwsoln03 tocHwsoln03 toc
Hwsoln03 toc
 
Chapter 2 2 1 1
Chapter 2 2 1 1Chapter 2 2 1 1
Chapter 2 2 1 1
 
Nfa vs dfa
Nfa vs dfaNfa vs dfa
Nfa vs dfa
 
Lecture 17- F19.pdf
Lecture 17- F19.pdfLecture 17- F19.pdf
Lecture 17- F19.pdf
 
Compiler Design File
Compiler Design FileCompiler Design File
Compiler Design File
 
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
4-Regular expression to Deterministic Finite Automata (Direct method)-05-05-2...
 
optimization of DFA
optimization of DFAoptimization of DFA
optimization of DFA
 
A class of boundary value methods for the complex delay differential equation
A class of boundary value methods for the complex delay differential equationA class of boundary value methods for the complex delay differential equation
A class of boundary value methods for the complex delay differential equation
 
Lecture 03 lexical analysis
Lecture 03 lexical analysisLecture 03 lexical analysis
Lecture 03 lexical analysis
 
Let us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solutionLet us c (by yashvant kanetkar) chapter 1 solution
Let us c (by yashvant kanetkar) chapter 1 solution
 
aho corasick paper study note
 aho corasick paper study note aho corasick paper study note
aho corasick paper study note
 
Laplace
LaplaceLaplace
Laplace
 
finite_automata.ppt
finite_automata.pptfinite_automata.ppt
finite_automata.ppt
 
1406
14061406
1406
 
02. chapter 3 lexical analysis
02. chapter 3   lexical analysis02. chapter 3   lexical analysis
02. chapter 3 lexical analysis
 
Comparative Report Ed098
Comparative Report Ed098Comparative Report Ed098
Comparative Report Ed098
 

More from bolovv

Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
bolovv
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
bolovv
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
bolovv
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
bolovv
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
bolovv
 
Chapter One
Chapter OneChapter One
Chapter One
bolovv
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)
bolovv
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
bolovv
 
Chapter 1 1
Chapter 1 1Chapter 1 1
Chapter 1 1
bolovv
 

More from bolovv (9)

Chapter Three(2)
Chapter Three(2)Chapter Three(2)
Chapter Three(2)
 
Chapter Three(1)
Chapter Three(1)Chapter Three(1)
Chapter Three(1)
 
Chapter Seven(2)
Chapter Seven(2)Chapter Seven(2)
Chapter Seven(2)
 
Chapter Eight(3)
Chapter Eight(3)Chapter Eight(3)
Chapter Eight(3)
 
Chapter Five(2)
Chapter Five(2)Chapter Five(2)
Chapter Five(2)
 
Chapter One
Chapter OneChapter One
Chapter One
 
Chapter Seven(1)
Chapter Seven(1)Chapter Seven(1)
Chapter Seven(1)
 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
 
Chapter 1 1
Chapter 1 1Chapter 1 1
Chapter 1 1
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Chapter 2 2 1 2

  • 1. Example 2.16: consider the NFA of Figure 2.8 M ε-closure of M (S) S′a S′b 1 1,2,6 3,7 3,7 3,4,7,8 5 5 5,8 a b 1
  • 2. Example 2.17: consider the NFA of Figure 2.9 (regular expression letter(letter|digit)*) M ε-closure of M (S) S′letter S′digit 1 1 2 2 2,3,4,5,7,10 6 8 6 4,5,6,7,9,10 6 8 8 4,5,7,8,9,10 6 8 le tte r 2
  • 3. 2.4.3 Simulating an NFA using the subset construction As mentioned at section 2.3. NFAs can be implemented in similar ways to DFAs, except that since NFAs are nondeterministic, there are potentially many different sequences of transitions that must be tried. A program that simulates an NFA must store up transitions that have not yet been tried and backtrack to them on failure. An other way of simulating an NFA is to use the subset construction, but instead of constructing all the states of the associated DFA, we construct only the state at each point that is indicated by the next input character. The advantage: we may not need to construct the entire DFA. In example 2.16, the input string consisting of the single character a. a b The disadvantage: a state may be constructed many times, if the path contains loops. In example 2.17, given the input string r2d3 2.4.4 Minimizing the number of states in a DFA The process we have described of deriving a DFA algorithmically from a regular expression has the unfortunate property that the resulting DFA may be more complex than necessary. For example 2.15 we derived the DFA for the regular expression a*: whereas the DFA will do as well. a 3
  • 4. An important result from automata theory states that, given any DFA, there is an equivalent DFA containing a minimum number of states, and, that this minimum-state DFA is unique (except for renaming of states). It is also possible to directly obtain this minimum-state DFA from any given DFA. Given the algorithm as follow: (1) It begins with the most optimistic assumption possible. It creates two sets, one consisting of all the accepting states and the other consisting of all the non-accepting states. (2) Given this partition of the states of the original DFA, consider the transitions on each character a of the alphabet.  If all accepting states have transitions on a to accepting states, then this defines an a-transition from the new accepting state (the set of all the old accepting states) to itself.  If all accepting states have transitions on a to non-accepting states, then this defines an a-transition from the new accepting state to the new non- accepting state (the set of all the old non-accepting stales).  On the other hand, if there are two accepting states s and t that have transitions on a that land in different sets, then no a-transition can be defined for this grouping of the states. We say that a distinguishes the states s and t  We must also consider error transitions to an error state that is non- accepting. If there are accepting states s and t such that s has an a-transition to another accepting state, while t has no a-transition at all (i.e., an error transition), then a distinguishes s and t. (3) If any further sets are split, we must return and repeat the process from the beginning. This process continues until either all sets contain only one element (in which case, we have shown the original DFA to be minimal) or until no further splitting of sets occurs. 4
  • 5. le tte r Example 2.18: The regular expression letter(letter|digit)* The accepting sets {2,3,4,5,7,10},{4,5,6,7,9,10},{4,5,7,8,9,10} The nonaccepting sets {1} The following minimum-state DFA : letter digit Example 2.19: the regular expression (a| ε)b* The accepting sets {1,2,3} The non-accepting sets state 1 has an a-transition to an accepting state, while states 2 .and 3 have no a-transition (or, rather, an error transition on a to the error nonaccepting state). Thus, a distinguishes state 1 from states 2 and 3, and we must repartition the states into the sets {1} and {2,3}. Now we begin over. The set {1} cannot be split further, so we no longer consider it. Now the states 2 and 3 cannot be distinguished by either a or b. 5