Skip to content

TOC Finite Automata

The computation power of this model is rather weak. Because it can only use a limited (finite) memory. But it is also useful in some applications.

DFA

+ Deterministic finite automata $DFA$

A deterministic finite automata (DFA) is a 5-tuple (Q,Σ,δ,q0,F) , where

  • Q is a finite set called states,
  • Σ is a finite set called alphabet,
  • δ:Q×ΣQ is the transition function,
  • q0Q is the start state (also called initial state), and
  • FQ is the set of accept states (final states).

The transition function δ can also be represented as a transition table. The table has |Q| rows and |Σ| columns. The value in each entry is a state. δ is a total function. So, every entry has a value. The input of a DFA is a string in the language Σ. The output of a DFA is only accept or reject.

Suppose w=w1w2wn is a string in Σ. The DFA M accepts w if and only if:

δ(q0,w1)=qs1δ(qs1,w2)=qs2δ(qsn1,wn)=qsnF

Each qsi is a state of M. Each δ(qsi,wi+1)=qsi+1 is a transition. qsn is a final state in F.

The sequence of transitions can also be expressed as:

δ(δ(δ(q0,w1),w2),wn)F

Remember, a DFA can be represented as a state graph. The features of the graph are listed:

  • A state is in a circle.
  • A transition is an arc from the current state to the next state.
  • The input symbol required by a transition is the label of the arc.
  • The initial state is pointed by an arrow.
  • Each final state is double circled.

Example

Let M1=({q0,q1},{0,1},δ,q0,{q1}) be a DFA, where the transition function δ is:

01
q0q0q1
q1q0q1
L(M1)={w{0,1}w end with 1’s}.

If A is the set of all strings that M accepts, then:

  • A is the language of machine M;
  • L(M)=A;
  • M recognizes A.

For example:

L(M1)={ww ends with a 1}.

A language is regular if it is recognized by some DFA (Deterministic Finite Automaton).

NFA

+ Nondeterministic finite automata $NFA$.

An NFA (Nondeterministic Finite Automaton) is a 5-tuple (Q,Σ,δ,q0,F), where:

  • Q is the set of states;
  • Σ is the alphabet;
  • δ:Q×ΣP(Q) is the transition function;
  • q0Q is the start state; and
  • FQ is the set of final states.

Suppose M is an NFA to recognize the language A.

  • If w is a string in the language A:

    • Then there exists a "way" to reach the final state;
    • It's also possible to reach a non-final state.
  • But if w is not a string in the language A:

    • Then there is no way to reach the final state.

Please pay attention to the quantifiers.

Different between DFA and NFA

The difference between a DFA and an NFA is the transition function δ.

  • DFA: δ:Q×ΣQ
  • NFA: δ:Q×ΣP(Q)
    • P(Q) is the power set of Q.

This difference allows:

  • One state to transition to zero, one, or multiple states by taking one input symbol.

εMoves

Automatas can be further upgraded by a special transition.

+ $\epsilon-Move$

An ϵMove is a transition from one state to another state by taking no input symbol.

Such automata is defined.

+ NFA with $\epsilon-Move$

An NFA with ε-moves is the same as an NFA (without ε-moves) except the transition function:

δ:Q×Σ{ε}P(Q)

Later, we will see that ε-moves allow us to recursively construct NFAs, which is... elegant.

Equivalence of DFA and NFA

Power

Let M1 and M2 be two computation models. M1 is as powerful as M2 if:

  • For all languages L, L is recognized by some machines in M1 if and only if it is recognized by some machines in M2.

M1 is more powerful than M2 if there is a language L which can be recognized by some machines in M1 but no machine in M2.

Note: A computation model is a set of all machines of the same type.

+ Theorem

DFA, NFA, and NFA with ε-moves are of the same computation power.

For convenience, we denote the ordering on the power by =pow, <pow, pow, etc. Trivially,

+ Lemma

DFApowNFApowNFAε

Next, we only need to show NFAεpowDFA.

It seems the content repeats the explanation for converting NFAε to a DFA and introduces the concept of ε-closure more formally. Here's a summary in Markdown format for your reference:

The Intuition of the Proof:

  • For every NFAε, we can construct a DFA that recognizes the same language.
  • This is equivalent to the process of converting an NFA to an equivalent DFA.

+ Def: $\varepsilon$-closure

Let N=(Q,Σ{ε},δ,q0,F) be an NFAε.
The ε-closure of a state q, denoted E(q), is defined as:

E(q)={q}δ(q,ε)δ(δ(q,ε),ε)
  • E(q) represents the set of all states that can be reached starting from q only using ε-transitions.
  • This closure includes q itself and any other states reachable via one or more ε-moves.
  • Alternative Name: The ε-closure is sometimes referred to as the Kleene Star or Kleene Closure.

+ Def: $\upvarepsilon-Closure$ of a Set of States

Let R be a set of states for a given NFA. The ε-closure of R, denoted E(R), is:

E(R)=qRE(q)

This means the ε-closure of R is the union of the ε-closures of all individual states in R. E(q) is the set of states reachable from q using only ε-transitions.

+ Def: **$a$-Move of a Set of States:**

Let R be a set of states, and let a be a symbol for a given NFA. The a-move of R, denoted δ(R,a), is:

δ(R,a)=qRE(δ(q,a))

This describes all the states reachable by:

  1. First making an a-transition from any state q in R, and
  2. Then taking all ε-transitions from those resulting states.

NOTE: δ(q,a) gives the set of states reachable by consuming the symbol a.

Construction Algorithm

Let N=(Q,Σ,δ,q0,F) be an NFAε. We construct a DFA D=(Q,Σ,δ,q0,F), where:

  • Q=P(Q)
  • δ:P(Q)×ΣP(Q) such that:δ(R,a)={qQrR,qE(δ(r,a))}
  • q0=E(q0)
  • F={RQRF}

States (Q):

  • Q=P(Q), the power set of Q.
  • Each state in D is a subset of the states in N.

Transition Function (δ):

δ:P(Q)×ΣP(Q), defined as: $$\delta'(R, a) = { q \in Q \mid \exists r \in R, q \in E(\delta(r, a)) }$$

  • For each state RQ and symbol aΣ:
  • Find all states q reachable by an a-move from some rR, considering ε-closures.

Start State (q0):

  • q0=E(q0), the ε-closure of the initial state q0 of N.

Final States (F):

  • F={RQRF}.
  • A subset R of states is a final state in D if it includes any final state of N.

Ensures D captures all possible behaviors of N, including ε-transitions. Uses the power set of Q as the state space to simulate nondeterminism deterministically.


Pseudocode

pseudo
\begin{algorithm}
\caption{Convert NFA$_\varepsilon$ to DFA}
\begin{algorithmic}
    \State \textbf{Input:} An NFA$_\varepsilon$ $N = (Q, \Sigma, \delta, q_0, F)$
    \State \textbf{Output:} A DFA $D = (Q', \Sigma, \delta', q_0', F')$
    \State $Q' \gets \{E(q_0)\}$, $E(q_0)$ is unmarked, and $\delta' \gets \emptyset$
    \While{there exists an unmarked state $R \in Q'$}
        \State Mark $R$
        \For{each symbol $a \in \Sigma$}
            \State $U \gets E(\delta(R, a))$
            \If{$U \notin Q'$}
                \State Add $U$ to $Q'$
            \EndIf
            \State Add $\delta'(R, a) = U$ to $\delta'$
        \EndFor
    \EndWhile
    \State $q_0' \gets E(q_0)$
    \State $F' \gets \{R \mid R \text{ has a final state in } F\}$
    \State \Return $D \gets (Q', \Sigma, \delta', q_0', F')$
\end{algorithmic}
\end{algorithm}

Example

Let’s try to convert this NFA to DFA.

Initially

Suppose the unmarked states are red.

Q={E(q0)={q0,q2}},δ={}

Step 1

E(δ({q0,q2},0))=E({q0})={q0,q2}E(δ({q0,q2},1))=E({q1})={q1}

Step 2

E(δ({q1},0))=E({q1,q2})={q1,q2}E(δ({q1},1))=E({q2})={q2}

Step 3

E(δ({q1,q2},0))=E({q0,q1,q2})={q0,q1,q2}E(δ({q1,q2},1))=E({q2})={q2}

Step 4

E(δ({q2},0))=E({q0})={q0,q2}E(δ({q2},1))=E({})={}

Step 5

E(δ({q0,q1,q2},0))=E({q0,q1,q2})={q0,q1,q2}E(δ({q0,q1,q2},1))=E({q1,q2})={q1,q2}

E(δ({},0))=E({})={}E(δ({},1))=E({})={}

Finally

{q0,q2} and {q0,q1,q2} are final states.

Rename the states to make the DFA more readable and beautiful: q0,q1,q2,q3,q4,q5.

q5 is a trap state because it has no valid transitions.