1 / 33

Non-Deterministic Finite Automata

Non-Deterministic Finite Automata. Formal Definition of DFA. A DFA consists of: Alphabet  A set of states Q A transition function δ : Q   Q One start state q 0 One or more accepting states F  Q

finna
Télécharger la présentation

Non-Deterministic Finite Automata

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Non-Deterministic Finite Automata

  2. Formal Definition of DFA • A DFA consists of: • Alphabet • A set of statesQ • A transition functionδ : Q  Q • One start state q0 • One or more accepting states F  Q • Language accepted by a DFA is the set of strings such that DFA ends at an accepting state • Each string is c1c2…cn with ci   • States are qi = δ(qi-1,ci ) for i=1…n • qn is an accepting state

  3. q2 1  q1 q1 q2 q3 1 empty string transition nondeterministic transition NFA and -NFA • Nondeterministic Finite Automata • Same input may produce multiple paths • Allows transition with an empty string or transition from one state to different states given a character

  4. The Language Accepted by a NFA

  5. EXAMPLE

  6. Accept strings containing a 1 in the third position from the back 0,1 0, 1 1 2 3 4 1 0,1 Another Example

  7. RECAP: How does NFA work? • Start in start state • Read a symbol, clone a machine for each matching transition • If a symbol is read and there is no way to exit from a state, then that machine dies • At end of input if any machine accepts then accept

  8. RECAP Definition: NFA • An NFA is defined by a 5-tuple, with • Alphabet • A set of statesQ • A transition functionδ : Q Σ P(Q) • One start stateq0 • One or more accepting states F  Q • Notation: P(Q) is power set of Q • What is the difference from DFA?

  9. RECAP Nondeterministic Transition • The functionδ : Q Σ P(Q)is the key difference! • When reading symbol `a’ while in state q, it may go to one of the states in δ(q,a)Q. • Can δ(q,a) map to empty set?

  10. RECAP Languages • Language accepted by a NFA is the set of strings such that NFA ends at an accepting state • Each string of language is c1c2…cn with ciΣ(possibly with ε) • States are qi  δ(qi-1,ci) for i=1…n • qn is an accepting state

  11. RECAP DFA = NFA • Theorem: For every language L accepted by an NFA, there is a DFA that accepts L. • In other words, DFA and NFA are equivalent computational models. • Proof idea: When keeping track of nondeterministic computation of NFA N, use many ‘fingers’ to point at the set of states of N that can be reached on a given input string. We can simulate this computation with a DFA M with state space P(Q).

  12. 0,1 0, 1 1 2 3 4 1 0,1 Proof of DNA=NFA • More formal proof: Let A be the language recognized by the NFA N = (Q,Σ,δ,q0,F). Define the DFA M = (Q’,Σ,δ’,q’0,F’) by • Q’ = P(Q) • δ’(R,a) = { qQ | qδ(r,a) for an rR } • q’0 = { q0 } • F’ = {RQ’ | R contains an accept state of N}

  13. How does NFA work? • Start in start state • If any  transitions, clone a machine for each  transition • Read a symbol, clone a machine for each matching transition • If a symbol is read and there is no way to exit from a state, then that machine dies • At end of input if any machine accepts then accept

  14. 0,1 0,1 0,  1 1 2 3 4 1 Example • Accept strings containing either 101 or 11 as a substring

  15. How would this NFA work? 0,1 0,1 0,  1 1 2 3 4 1 Example: Read: 010110

  16. 1 0 1 1 1 2 3 0 1 3 1 1 2 3 4 1 2 1 3 4 4 0 1 4 4 Read: 010110

  17. Definition: εNFA • An NFA is defined by a 5-tuple, with • Alphabet • A set of statesQ • A transition functionδ : Q Σε P(Q) • One start stateq0 • One or more accepting states F  Q • Notation: Σε = Σ{ε}; P(Q) is power set of Q • What is the difference from DFA?

  18. Nondeterministic Transition • The functionδ : Q Σε P(Q)is the key difference! • When reading symbol `a’ while in state q, it may go to one of the states in δ(q,a)Q. • ε in Σε allows empty-string transitions • Can δ(q,a) map to empty set?

  19. Languages • Language accepted by a NFA is the set of strings such that NFA ends at an accepting state • Each string of language is c1c2…cn with ciΣε (possibly with ε) • States are qi  δ(qi-1,ci) for i=1…n • qn is an accepting state

  20. The Golden Chain εNFA  NFA  DFA REGEX

  21. EpsilonNFA NFA  DFA

  22. Regular Expressions

More Related