inf2a converting from nfas to dfas and closure properties
play

Inf2A: Converting from NFAs to DFAs and Closure Properties Stuart - PowerPoint PPT Presentation

Non-Deterministic Finite Automata The Conversion Theorem Closure Properties Summary Inf2A: Converting from NFAs to DFAs and Closure Properties Stuart Anderson School of Informatics University of Edinburgh October 13, 2009 university-logo


  1. Non-Deterministic Finite Automata The Conversion Theorem Closure Properties Summary Inf2A: Converting from NFAs to DFAs and Closure Properties Stuart Anderson School of Informatics University of Edinburgh October 13, 2009 university-logo 1/43

  2. Non-Deterministic Finite Automata The Conversion Theorem Closure Properties Summary Starter Questions Can you devise a way of testing for any FSM M whether 1 L ( M ) = ∅ ? Can you devise a way of testing for any pair of FSMs M 2 and M ′ whether L ( M ) = L ( M ′ ) ? university-logo 2/43

  3. Non-Deterministic Finite Automata The Conversion Theorem Closure Properties Summary Outline Non-Deterministic Finite Automata 1 NFA - the definitions NFA: Example The Conversion Theorem 2 Converting from NFAs to DFAs Example: Converting from an NFA to a DFA Closure Properties 3 Demonstrating Closure under various operators Closure: Example Summary 4 university-logo 3/43

  4. Non-Deterministic Finite Automata The Conversion Theorem NFA - the definitions Closure Properties NFA: Example Summary A non-deterministic automaton a,b a a b 1 0 2 3 Formally: � { 0 , 1 , 2 , 3 } , { a , b } , 0 , { 3 } , ∆ � N = , where the transition relation ∆ is given by the following table: ∆ a b 0 { 0 , 1 } { 0 } 1 ∅ { 2 } { 3 } ∅ 2 3 ∅ ∅ university-logo 4/43

  5. Non-Deterministic Finite Automata The Conversion Theorem NFA - the definitions Closure Properties NFA: Example Summary Non-deterministic Finite Automata Definition: A nondeterministic finite automaton (or NFA ) is a tuple N = ( Q , Σ , q 0 , F , ∆) consisting of: a finite set Q of states , 1 a finite alphabet Σ , 2 a distinguished starting state q 0 ∈ Q , 3 a set F ⊆ Q of final states (the ones that indicate 4 acceptance), a description ∆ of all the possible transitions . 5 ∆ must be given by a table that answers the following question: “Given a state q and an input symbol a , what are the possible next states?” university-logo ∆ is called the transition function or transition relation . 6/43

  6. Non-Deterministic Finite Automata The Conversion Theorem NFA - the definitions Closure Properties NFA: Example Summary The Language of an NFA As opposed to a DFA, an NFA may have several possible computations for the same input string — or it may get stuck and have no (complete) computation at all. An NFA N is said to accept a string x if there is at least one computation of N on input x that leads to an accepting final state. The language recognized by an NFA N = ( Q , Σ , q 0 , F , ∆) is the language x ∈ Σ ∗ | N accepts x � � L ( N )= . university-logo 7/43

  7. Non-Deterministic Finite Automata The Conversion Theorem NFA - the definitions Closure Properties NFA: Example Summary Example a,b a a b 1 2 3 0 Two possible computations of this NFA on input aaaba : a a a b a 0 − → 0 − → 0 − → 0 − → 0 − → 0 a a a b a 0 − → 0 − → 0 − → 1 − → 2 − → 3 The NFA accepts the language � xaba | x ∈ { a , b } ∗ � . university-logo 9/43

  8. Non-Deterministic Finite Automata The Conversion Theorem NFA - the definitions Closure Properties NFA: Example Summary Example 1 0 2 0−9 0 1 1 0 2 1 1 1 0 university-logo 10/43

  9. Non-Deterministic Finite Automata The Conversion Theorem NFA - the definitions Closure Properties NFA: Example Summary NFAs with ε -Transitions ε -transitions are transitions not triggered by any input symbol. If in a state q an ε -transition to a state q ′ is possible, then whenever the automaton reaches state q in a computation it can immediately proceed to state q ′ without needing any further input. To descibe this formally the function ∆ is defined for Σ ∪ { ε } . Example: ε ε ε ε a b a c 3 4 0 1 2 An NFA with ε -transitions recognizing the language { ε, c , ac , bac , abac } . university-logo 11/43

  10. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary The languages of NFAs Obvious fact 1: Any language recognized by some DFA can also be recognized by some NFA. Obvious fact 2: Any language recognized by some NFA can also be recognized by some NFA with ε -transitions. university-logo 12/43

  11. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary The Conversion Theorem Theorem: Any language accepted by some NFA with ε -transitions is also accepted by some DFA. Therefore, every language accepted by an NFA, with or without ε -transitions, is regular. university-logo 14/43

  12. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary Proof: The Powerset Construction Let N = ( Q , Σ , q 0 , F , ∆) be an NFA. Idea: Simulate all possible computations of N “in parallel”. Construction: Let M = ( S , Σ , s 0 , F ′ , δ ) , where S = P ( Q ) = { s | s ⊆ Q } (the powerset of Q ) s 0 = { q 0 } ∪ { q | q can be reached from q 0 using only ε -transitions } δ is defined by δ ( s , a ) = set of all states reachable from a state in s by one a -transition and ε -transitions. F ′ = { s ∈ S | s ∩ F � = ∅} . university-logo 15/43

  13. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary The conversion algorithm Construct the start state s 0 consisting of q 0 and all states 1 of N that can be reached from q 0 by one or several ε -transitions. Mark s 0 as “unfinished”. While there still are “unfinished” states: 2 Take an “unfinished” state s . 1 For each a ∈ Σ , let 2 δ ( s , a ) = set of all states reachable from a state in s by one a -transition and ε -transitions � = q ∈ s set of all states reachable from q by one a -transition and ε -transitions If δ ( s , a ) is neither “finished” nor “unfinished” yet, then mark δ ( s , a ) as “unfinished”. Mark s as “finished”. 3 Mark all states that contain a final state from N as final 3 university-logo states of M . 16/43

  14. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary An example conversion 1 0 1 3 ε ε ε 0 7 6 ε 0 ε 1 0 2 4 5 ε The start state: s 0 = { 0 , 1 , 2 } . university-logo 18/43

  15. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary Computing the transition table δ δ 0 1 0 1 { 0 , 1 , 2 } { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } ∅ δ δ 0 1 0 1 { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } ∅ ∅ ∅ ∅ { 6 , 7 } { 6 , 7 } { 2 , 3 , 5 , 6 } { 2 , 3 , 5 , 6 } university-logo 19/43

  16. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary δ 0 1 { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } ∅ ∅ ∅ { 6 , 7 } { 6 , 7 } ∅ { 2 , 3 , 5 , 6 } δ 0 1 { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } ∅ ∅ ∅ { 6 , 7 } { 6 , 7 } ∅ { 2 , 3 , 5 , 6 } { 4 , 6 , 7 } { 3 , 6 } { 4 , 6 , 7 } { 3 , 6 } university-logo 20/43

  17. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary δ 0 1 { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } ∅ ∅ ∅ { 6 , 7 } { 6 , 7 } ∅ { 2 , 3 , 5 , 6 } { 4 , 6 , 7 } { 3 , 6 } { 4 , 6 , 7 } { 6 , 7 } { 2 , 5 , 6 } { 3 , 6 } { 2 , 5 , 6 } university-logo 21/43

  18. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary δ 0 1 { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } ∅ ∅ ∅ { 6 , 7 } { 6 , 7 } ∅ { 2 , 3 , 5 , 6 } { 4 , 6 , 7 } { 3 , 6 } { 4 , 6 , 7 } { 6 , 7 } { 2 , 5 , 6 } { 3 , 6 } { 6 , 7 } { 3 , 6 } { 2 , 5 , 6 } university-logo 22/43

  19. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary δ 0 1 { 0 , 1 , 2 } { 3 , 4 , 6 } ∅ { 3 , 4 , 6 } { 6 , 7 } { 2 , 3 , 5 , 6 } ∅ ∅ ∅ { 6 , 7 } { 6 , 7 } ∅ { 2 , 3 , 5 , 6 } { 4 , 6 , 7 } { 3 , 6 } { 4 , 6 , 7 } { 6 , 7 } { 2 , 5 , 6 } { 3 , 6 } { 6 , 7 } { 3 , 6 } { 2 , 5 , 6 } { 4 , 6 , 7 } ∅ The final states: F ′ = { s ∈ S | s ∩ { 7 } � = ∅} � � = { 6 , 7 } , { 4 , 6 , 7 } . university-logo 23/43

  20. Non-Deterministic Finite Automata The Conversion Theorem Converting from NFAs to DFAs Closure Properties Example: Converting from an NFA to a DFA Summary The resulting DFA 0,1 1 {0,1,2} φ 0 1 1 0 0 {3,4,6} {2,5,6} {6,7} 0 1 1 0 0 1 1 {2,3,5,6} {3,6} {4,6.7} university-logo 0 24/43

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend