Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nondeterministic Finite Automata

Similar presentations


Presentation on theme: "Nondeterministic Finite Automata"— 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 A Nondeterministic Solution to the Tricky Automaton
1 0, 1

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 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 Example: A DFA A DFA that accepts all strings that contain 010 or do not contain 0. 1 0, 1

11 Converting a Relation into a Function
It is possible to rewrite a relation R from A to B as a function f 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

15 Examples of Converting an NFA to a DFA
Use this idea to rewrite the relation  of the NFA for all strings that contain 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 Converting an NFA to a DFA
Convert the following NFA to an equivalent DFA. 1 e

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.


Download ppt "Nondeterministic Finite Automata"

Similar presentations


Ads by Google