nondeterministic finite automata
play

Nondeterministic Finite Automata CSCI 3130 Formal Languages and - PowerPoint PPT Presentation

Nondeterministic Finite Automata CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Fall 2018 Chinese University of Hong Kong 1/22 Example from last lecture with a simpler solution q 2 0 1 0 or q 0 q 1 0 1 1 1 0 0 1 Three


  1. Nondeterministic Finite Automata CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Fall 2018 Chinese University of Hong Kong 1/22

  2. Example from last lecture with a simpler solution q 2 0 1 0 or q 0 q 1 0 1 1 1 0 0 1 Three weeks later: DFA minimization 1 0 2/22 q 11 q 0 q 1 q 00 q 01 q 10 0 1 0 1 1 0 1 0 Construct a DFA over { 0 , 1 } that accepts all strings ending in 01 q ε

  3. Another example from last lecture or q 0 q 1 q 2 q 2 1 0 1 0 1 0 0 1 3/22 Construct a DFA over { 0 , 1 } that accepts all strings ending in 101

  4. String matching DFAs q 2 (won’t cover in class) Boyer–Moore (BM) and Knuth–Morris–Pratt (KMP) matching DFA and execute the DFA: 1 0 0 1 0 1 0 1 q 2 Ending in 01 q 1 q 0 1 0 0 1 1 0 q 2 q 1 q 0 4/22 Ending in 101 Fast string matching algorithms to turn a pattern into a string

  5. Nondeterminism

  6. In a few lectures 1 We’ll answer this question in the next few lectures What problems can fjnite state machines solve? 1 0 0 0 q 0 1 0 1 q 2 q 2 q 1 5/22 Useful to consider hypothetical machines that are nondeterministic

  7. Even easier with guesses Suppose we could guess when the input string has only 3 symbols left Accept strings ending in 101: 3 symbols left 1 0 1 0 1 0 6/22 This is not a DFA!

  8. Nondeterministic fjnite automata A machine that allows us to make guesses q 0 q 1 q 2 q 3 0,1 1 0 1 by the same symbol 7/22 Each state can have zero, one, or more outgoing transitions labeled

  9. Choosing where to go q 0 q 1 q 2 q 3 0,1 1 0 1 8/22 State q 0 has two transitions labeled 1 Upon reading 1, we have the choice of staying at q 0 or moving to q 1

  10. Ability to choose q 0 q 1 q 2 q 3 0,1 1 0 1 Upon reading 1 at q 1 , die; upon reading 0, continue to q 2 9/22 State q 1 has no transition labeled 1

  11. Ability to choose q 0 q 1 q 2 q 3 0,1 1 0 1 Upon reading 0 or 1 at q 3 , die 10/22 State q 1 has no transition going out

  12. Meaning of NFA 101 1 0 1 0,1 end of input we are at the Check that see the pattern q 0 If so, guess we will from end of input 3 symbols away Guess if we are q 3 q 2 q 1 11/22

  13. How to run an NFA q 0 q 1 q 2 q 3 0,1 1 0 1 input: 01101 12/22 The NFA can have several active states at the same time NFA accepts if at the end, one of its active states is accepting

  14. Example containing the pattern 001 somewhere 11001010, 001001, 111001 should be accepted should not 13/22 Construct an NFA over alphabet { 0 , 1 } that accepts all strings ε , 000, 010101

  15. Example containing the pattern 001 somewhere q 0 q 1 q 2 q 3 0,1 0 0 1 0,1 14/22 Construct an NFA over alphabet { 0 , 1 } that accepts all strings

  16. Defjnition where • Q is a fjnite set of states Differences from DFA: 15/22 A nondeterministic fjnite automaton (NFA) is a 5 -tuple ( Q , Σ , δ, q 0 , F ) • Σ is an alphabet • δ : Q × (Σ ∪ { ε } ) → subsets of Q is a transition function • q 0 ∈ Q is the initial state • F ⊆ Q is a set of accepting states • transition function δ can go into several states • allows ε -transitions

  17. Language of an NFA The NFA accepts string x if there is some path that, starting from q 0 , ends at an accepting state as x is read from left to right The language of an NFA is the set of all strings accepted by the NFA 16/22

  18. q 0 q 1 q 2 a b a accepts a, b, aab, bab, aabab, … rejects 17/22 ε -transitions ε -transitions can be taken for free: ε ε , aa, ba, bb, …

  19. Example initial state q 0 q 2 q 1 q 0 states q 0 0 inputs 1 18/22 q 2 0 0 q 1 ε ,1 ε table of transition function δ alphabet Σ = { 0 , 1 } ε states Q = { q 0 , q 1 , q 2 } ∅ { q 1 } { q 1 } { q 0 , q 1 } ∅ { q 2 } accepting states F = { q 2 } ∅ ∅ ∅

  20. Some computational paths of the NFA q 0 q 2 1 4 0 3 0 2 5 q 1 4 q 2 1 3 0 2 0 4 5 q 0 q 1 19/22 q 0 q 0 q 1 q 2 1 0 0 2 3 00 q 1 q 2 1 0 0 2 ε ,1 ε ε ε ,1 ε ε ,1 ε ε ,1 ε

  21. Some computational paths of the NFA 1 001 0 4 11 q 0 q 1 q 2 0 3 0 q 0 q 1 q 2 1 0 0 2 0 2 1 0 q 0 q 1 q 2 1 4 0 3 2 5 101 q 0 q 1 q 2 20/22 ε , 1 ε ε ,1 ε ε ,1 ε ε ,1 ε

  22. Language of this NFA q 0 q 1 q 2 0 0 What is the language of this NFA? 21/22 ε ,1 ε

  23. 22/22 0 0 0 1 1 1 1 0 odd number of 1s Construct an NFA that accepts all strings with an even number of 0s even number of 0s s 1 s 0 r 1 r 0 q 0 or an odd number of 1s Example of ε -transitions

  24. 22/22 Construct an NFA that accepts all strings with an even number of 0s 1 1 1 0 0 0 odd number of 1s 0 even number of 0s s 1 s 0 r 1 r 0 q 0 or an odd number of 1s 1 Example of ε -transitions ε ε

Recommend


More recommend