NFAs, Minimization




CS154

Chris Pollett

Feb. 17, 2020

Outline

Nondeterministic Finite Automata

Example NFA

Example Image of an NFA

Formal Definition of an NFA

Example

Formal Definition of Accepts

Equivalence of NFAs and DFAs -- The Power Set Construction

Theorem Any language recognized by an NFA is recognized by some DFA.

Proof: Given an NFA `N= (Q, Sigma, delta, q_0, F)` we want to simulate how it acts on a string `w` with a DFA, `M= (Q', Sigma, delta', q_0', F')`. The idea is we want to keep track of what possible states it could be in after reading the first `m` characters of `w`. Let `Q'= P(Q)`, the power set of `Q`. The alphabet is the same. For each `R in Q'` (i.e., `R subseteq Q`) and `a in Sigma`, let `delta'(R, a) = {q in Q | q in E(delta(r,a)) \ mbox{for some} \ r in R}`. Here `E(q')` is the set of states reachable from `q'` following 0 or more `epsilon` transitions, for a set of states `Q''`, `E(Q'')` is the union of `E(q'')` for `q'' in Q''`. Let the new start state be `q_0'=E(q_0)`. Let `F' = {R in Q'| R \ mbox{contains an accept state of} \ N}`.

This construction is from the original NFA paper of Rabin and Scott (1959).

Example Conversion

Quiz

Which of the following is true?

  1. The state set of a DFA is allowed to be infinite.
  2. All transitions starting from a trap state map to the trap state.
  3. Our proof that regular languages are closed under union directly used the pigeonhole principle.

State Minimization

Procedure for Equivalence

  1. Remove all inaccessible states. This can be done by checking for each state if there is a simple path from the start state to it.
  2. Consider all pairs `(p,q)` of states. If `p in F` but `q !in F` or vice versa, then mark the pair `(p,q)` distinguishable.
  3. Repeat until no previously unmarked pairs are marked:
    1. For all pairs `(p,q)` and all `a in Sigma`, compute `delta(p,a) = p_a` and `delta(q,a) = q_a`. If the pair `(p_a,q_a)` is marked as distinguishable, mark `(p,q)` as distinguishable. Idea: if in `p` `q` on the same letter you transition to distinguishable states then `p` and `q` must be distinguishable.

Procedure to Build Minimal Automaton

  1. Use procedure of last slide to generate state equivalence classes for original automata.
  2. For each equivalence class `[p] = {q | p~_I q}` create a new state.
  3. For each transition rule `delta(r,a)=s` of the original machine, add a transition `delta([r],a)=[s]`.
  4. The initial state of the new machine is `[q_0]` where `q_0` was the state of the machine we are trying to minimize.
  5. The final states of the new machine is the set `{[f] | f in F}`.

The first procedure for minimizing finite automata was given in Huffman 1954 (J. Franklin Institute. Vol 257. Iss. 3-4).

Our procedure above probably runs in quadratic time, the best known algorithm is `O(n log n)` due to Hopcroft 1971.