1 / 19

Nondeterministic Finite Automata

Nondeterministic Finite Automata. Section 2.2 Wed, Sep 22, 2004. A Tricky DFA. Consider a DFA A 1 that accepts any string containing 010. Consider a second DFA A 2 that accepts any string containing 101. How would we design a DFA that accepts any string containing both 010 and 101?

briangarcia
Download Presentation

Nondeterministic 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. Nondeterministic Finite Automata Section 2.2 Wed, Sep 22, 2004

  2. A Tricky DFA • Consider a DFA A1 that accepts any string containing 010. • Consider a second DFA A2 that accepts any string containing 101. • How would we design a DFA that accepts any string containing both 010 and 101? • The occurrences might be separate (…010…101…) or combined (…0101…).

  3. Nondeterminism • Nondeterminism means that the next move is not uniquely determined by the current state and the current input symbol. • In some cases, there is more than one possible transition to follow. • The automaton will follow the “right” one, i.e., the one that leads to acceptance, if there is one.

  4. A Nondeterministic Solution to the Tricky Automaton • By using nondeterminism, we may set up transitions from the initial state on • ‘0’ if it is the beginning of 010, but not 0101. • ‘0’ if it is the beginning of 0101. • ‘1’ if it is the beginning of 101, but not 1010. • ‘1’ if it is the beginning of 1010. • Otherwise, eat symbols.

  5. 0, 1 1 0 1 0 1 0 1 0 0 1 0, 1 0, 1 1 0 0 1 1 0 0 1 0 1 0, 1 A Nondeterministic Solution to the Tricky Automaton

  6. Nondeterministic Finite Automata • A nondeterministic finite automaton (NFA) is a quintuple (K, , , s, F) where • K is a finite set of states. •  is a finite input alphabet. • sK is the initial state. • FK is the set of final states. •  is the transition relation from K ( {e}) to K.

  7. DFA vs. NFA • The difference between a DFA and an NFA is that the function has been replaced by the relation. • This allows • Transitions such as (p, a, q1) and (p, a, q2) together, where q1q2. • Transitions such as (p, e, q), called “e-moves”. • Without reading a symbol, i.e., “reading” e, move from p to q.

  8. Acceptance by an NFA • An NFA accepts a string w if there exists a sequence of transitions from the initial state to a final state that processes w. • Note that there may also exist sequences that lead to non-final states. • The language of the NFA is the set of all strings that it accepts.

  9. Examples of NFAs • Design an NFA that accepts all strings containing 001100. • Design an NFA that accepts the strings 32, 33, …, 99, 100, …, 758. • Design an NFA that accepts all strings that either contain 010 or do not contain 0.

  10. 1 0, 1 0 0 1 0 1 0 1 Example: A DFA • A DFA that accepts all strings that contain 010 or do not contain 0.

  11. Converting a Relation into a Function • It is possible to rewrite a relationR from A to B as a functionf from 2A to 2B. • Define a function f : 2A2B as follows: • Given S2A, define f(S) = {bB | (a, b) R for some aS}. • In other words, f maps each subset S of A to everything in B that is related to some element in S.

  12. Example: Converting a Relation into a Function • Let A = {2, 3, 4, 5} and B = {6, 7, 8, 9}. • Define the relation R from A to B as (a, b) R if “a divides b.” • Then R = {(2, 6), (2, 8), (3, 6), (3, 9), (4, 8)}.

  13. Example of Converting a Relation to a Function • The function f : 2A 2B is • f() =  • f({2}) = {6, 8} • f({3}) = {6, 9} • f({4}) = {8} • f({5}) =  • f({2, 3}) = f({2, 3, 4, 5}) = {6, 8, 9} • f({2, 4}) = f({2, 4, 5}) = {6, 8} • f({2, 5}) = {6, 8} • f({3, 4}) = f({2, 3, 4, 5}) = {6, 8, 9}

  14. Example of Converting a Relation to a Function • f({3, 5}) = {6, 9} • f({4, 5}) = {8} • f({2, 3, 4}) = {6, 8, 9} • f({2, 3, 5}) = {6, 8, 9} • f({2, 4, 5}) = {6, 8} • f({3, 4, 5}) = {6, 8, 9} • f({2, 3, 4, 5}) = {6, 8, 9}

  15. Examples of Converting an NFA to a DFA • Use this idea to rewrite the relation  of the NFA for all strings that contain 001100 as the function  of an equivalent DFA.

  16. Equivalence of NFAs and DFAs • Theorem: For each NFA M there exists a DFA M' that is equivalent to M. • Outline of the proof: • Convert the relation  to the function . • Then form the “e-closure” of this set. • Let q be any state in M. • Define the e-closure of q to be all the states reachable from q by using only e-moves. E(q) = {p K | (q, e) M* (p, e)}.

  17. Proof, continued • Define '(S) = E((S)). • Define F' = {S 2K | S contains a final state}. •  Verify that (2K, Σ, δ', E(s), F'}) is a DFA that accepts the same language as M.

  18. 1 e 1 0 1 0 e e Converting an NFA to a DFA • Convert the following NFA to an equivalent DFA.

  19. Examples of Converting an NFA to a DFA • Design an NFA and a DFA for all strings that contain either 101 or 010. • Redesign the NFA for all strings that either contain 101 or do not contain 0 as a DFA. • Redesign the NFA that accepts the strings 32, 33, …, 99, 100, 101, …, 758 as a DFA.

More Related