<- previous    index    next ->

Lecture 4 Nondeterministic Finite Automata, NFA

 Important! nondeterministic has nothing to do with random,
            nondeterministic implies parallelism.

 The difference between a DFA and a NFA is that the state transition
 table, delta, for a DFA has exactly one target state but for a NFA has
 a set, possibly phi, of target states.

 Example of a NFA, Nondeterministic Finite Automata given
 by a) Machine Definition  M = (Q, sigma, delta, q0, F)
    b) Equivalent regular expression
    c) Equivalent diagram

 and example tree of states for input string 0100011
 and equivalent DFA, Deterministic Finite Automata for the first 3 states.

 Machine Definition  M = (Q, sigma, delta, q0, F)
 Q = { q0, q1, q2, q3, q4 } the set of states
 F = { q2, q4 }             the set of final states (accepting)
 sigma = { 0, 1 }           the input string alphabet
 q0 = q0                    the starting state

                          inputs
         delta    |    0    |    1    |
         ---------+---------+---------+
              q0  | {q0,q3} | {q0,q1} |
              q1  |   phi   |   {q2}  |
    states    q2  |   {q2}  |   {q2}  |
              q3  |   {q4}  |   phi   |
              q4  |   {q4}  |   {q4}  |

 The equivalent regular expression is  (0+1)*(00+11)(0+1)*
 This NFA represents the language L = all strings over {0,1} that
 have at least two consecutive 0's or 1's.


         Equivalent  NFA  diagram.


Note that state q3 does not go anywhere for an input of 1.
We use the terminology that the path "dies" if in q3 getting an input 1.

The tree of states this NFA is in for the input  0100011

                                                       input
                            q0
                           /  \                          0
                         q3    q0
                        dies  /  \                       1
                            q1    q0
                           dies  /  \                    0
                               q3    q0
                              /     /  \                 0
                            q4    q3    q0
                           /     /     /  \              0
                         q4    q4    q3    q0
                        /     /     dies  /  \           1
                      q4    q4          q1    q0
                     /     /           /     /  \        1
                   q4    q4          q2     q1   q0

                   ^     ^           ^
                   |     |           |
             accepting paths in NFA tree


 Construct a DFA equivalent to the NFA above using just the first
 three rows of delta.

 The DFA machine is M' = (Q', sigma, delta', q0', F')
 Q' = 2**Q, the power set of Q = { phi, {q0}, {q1}, {q2}, {q0,q1}, {q0,q2},
                                   {q1,q2}, {q0,q1,q2} }
      Note: read the eight elements of the set Q' as names of states of M'
            use [ ]  in place of { } if you prefer.

 F' = { {q2}, {q0,q2}, {q1,q2}, {q0,q1,q2} }
      Note: Include any group that contains a final state of the NFA.
  
 sigma is the same
 q0' = {q0}


                               sigma
         delta'    |     0       |      1      |
         ----------+-------------+-------------+
             phi   |    phi      |     phi     | never reached
            {q0}   |   {q0}      |   {q0,q1}   |
            {q1}   |    phi      |     {q2}    | never reached
 states     {q2}   |   {q2}      |     {q2}    | never reached
          {q0,q1}  |   {q0}      | {q0,q1,q2}  |
          {q0,q2}  | {q0,q2}     | {q0,q1,q2}  |
          {q1,q2}  |   {q2}      |     {q2}    | never reached
        {q0,q1,q2} | {q0,q2}     | {q0,q1,q2}  |

  Note: Some of the states in the DFA may be unreachable


  The delta' was constructed directly from delta.
  Using the notation f'({q0},0) = f(q0,0) to mean:
    in delta' in state {q0} with input 0  goes to the state
    shown in delta with input 0.  Take the union of all such states.
  Further notation, phi is the empty set so phi union the set A is just the set A.
  Some samples: f'({q0,q1},0) = f(q0,0) union f(q1,0) = {q0}
                f'({q0,q1},1) = f(q0,1) union f(q1,1) = {q0,q1,q2}
                f'({q0,q2},0) = f(q0,0) union f(q2,0) = {q0,q2}
                f'({q0,q2},1) = f(q0,1) union f(q2,1) = {q0,q1,q2}

  The sequence of states is unique for a DFA, so for the same input as
  above  0100011 the sequence of states is
  {q0}  0  {q0}  1  {q0,q1} 0  {q0}  0  {q0}  0  {q0}  1  {q0,q1}  1 {q0,q1,q2}

  This sequence does not have any states involving q3 or q4 because just
  a part of the above NFA was converted to a DFA. This DFA does not
  accept the string  00  whereas the NFA above does accept  00.

    <- previous    index    next ->

Other links

Go to top