Skip to content

3. NFAs

Jan 18, 2022

Nondeterministic Finite Automata

  • same symbol may have multiple transitions (or none) from a state
  • special transition with ϵ
  • if input cannot be consumed automaton halts
  • explore all paths: if any choice consumes all input symbols and ends in accept state, then the input is accepted
  • reject input if there is no computation of the NFA that accepts the string, i.e. when for all possible computation paths:

    • all the input is consumed and the automaton is in a non-accepting state, or
    • the input cannot be consumed
  • NFAs can express languages easier than DFAs (fewer states and transitions)

Formal definition

  • M=(Q,Σ,δ,q0,F) where
    • Q is set of states
    • Σ is input alphabet and ϵΣ
    • δ is transition function (non-deterministic)
    • q0 is initial state
    • F is set of accepting states (0 or more)

Transition function

  • δ(q,x)={q1,q2,...,qk}   (can be )
  • resulting states reached by following one transition with input symbol x

Extended transition function

  • extended transition function: δ(q,w)={q,...} applied on string w
  • special case: for any state q   =>   qδ(q,ϵ)
  • in general: qjδ(qi,w) there is a path from qj to qi and transition labels w

Language accepted by NFA

  • The language accepted by M is L(M)={w1,w2...,wn} where for each wm δ(q0,wm)={qi,...,qk,...,qj} and there is some qkF (accepting state)
  • NFA accepts the regular languages
  • equivalence of machines: machine M1 is equivalent to M2 if L(M1)=L(M2)
  • NFAs and DFAs have the same the same computation power i.e. they accept the same set of languages
  • Proof steps: show that Languages accepted by NFAs Regular languages
    • Languages accepted by NFAs Regular languages
      • every DFA is trivially a NFA
      • any language L accepted by a DFA is also accepted by NFA
    • Languages accepted by NFAs Regular languages
      • any NFA can be converted to an equivalent DFA
      • any language L accepted by NFA is also accepted by DFA

Converting NFA to DFA

  • input: an NFA M
  • output: an equivalent DFA M' with L(M)=L(M)
  • NFA has states q0,q1,q2,...
  • DFA has states from the power set ,{q0},{q1},{q0,q1},{q1,q2,q3},...

Steps

  1. initial state of NFA: q0 and δ(q,ϵ)={q0,...} initial state of DFA: {q0}

  2. for every DFA's state {qi,qj,...,qm}, compute in NFA (union):

    {qi,qj,...,qn}={δ(qi,a)δ(qj,a)...δ(qm,a)

    and add transitions to DFA: δ({qi,qj,...,q,},a)={qi,qj,...,qn}

  3. Repeat step 2 for every state in DFA and symbols in alphabet until no more states can be added to the DFA

  4. For every DFA's state {qi,qj,...,qm}, if some qj is accepting state in NFA, then {qi,qj,...,qm} is accepting state in DFA