A DFA is a machine with
Input string is given on the tape, one symbol per cell.
Machine starts in a default start state with its read head positioned at the start of tape.
In each computation step, the machine uses its current state and the symbol under its read head to determine which next state to transition to. It then transitions to the next state and moves right one cell.
Machine knows when it is at the end of input.
Some states are marked as special.
Input string is accepted iff the machine ends up in a special state.
A DFA \(M\) is a 5-tuple \((Q, \Sigma, \delta, q_0, F)\), where
A state/transition diagram is a (multi)digraph that depicts a DFA.
This diagram represents the DFA \(M=(Q, \Sigma, \delta, q_0, F)\), where
A string \(w\in \Sigma^*\) of length \(n\) is accepted by DFA \(M\) iff there exists a sequence of states \(r_0, r_1, \ldots, r_n\) such that
\(L(M)\), the language recognized by \(M\), is the set of all strings accepted by \(M\), i.e., \(L(M) = \{ w\in\Sigma^* : M \text{ accepts } w \}\).
Exercise. Show that \(ab\) and \(babb\) are accepted by this machine but \(aab\) and \(bbaa\) are not.
We use comma-separated list of symbols as a shorthand for parallel edges, each labelled by a symbol in the list.
We may even use ellipsis for understood omitted symbols.
Sipser also uses \(\Sigma\) to represent a list of all symbols from the alphabet.
An NFA differs slightly from a DFA in its program and how it computes.
Given the current state and the symbol under the read head, an NFA has a number of (possibly zero) states that it can transition to.
Moreover, in some specific states an NFA may change its current state without moving its read head.
A DFA computation is always successful; it either ends up in an accepting or non-accepting state. In contrast, an NFA computation can crash! This occurs when the machine is in a state and reading a symbol such that its program has no transition for that combination of state & symbol. Moreover, an NFA computation can get into an infinite loop. (How?)
A string is accepted by an NFA M if it has an accepting computation by M.
A nondeterministic finite automaton (NFA) \(M\) is a 5-tuple \((Q, \Sigma, \delta, q_0, F)\), where
A string \(w\in \Sigma^*\) of length \(n\) is accepted by \(M\) if and only if we can write \(w=y_1y_2\dots y_m\), where each \(y_i=\varepsilon\) or \(y_i\in\Sigma\), and there exists a sequence of states \(r_0, r_1, \ldots, r_m\) such that
The set of all strings accepted by \(M\) is the language \(L(M)\) recognized by \(M\), i.e., \(L(M) = \{ w\in\Sigma^* : M \text{ accepts } w \}\).
Note that \(m\ne n\) is possible. (Why?)
In a state/transition diagram for a DFA where \(\Sigma\) has \(n\) symbols, every state has exactly \(n\) edges leaving it, one edge per symbol in \(\Sigma\). In a state/transition diagram for an NFA, on the other hand, some state may have more or fewer than \(n\) edges leaving it. Moreover, two distinct edges leaving the same state may have the same label, and some edge may be labelled with \(\varepsilon\).
If a string \(w\) is accepted by a DFA, then there exists a unique path from the start state to a final state that traces out \(w\). On the other hand, if a string \(w\) is accepted by an NFA, then there exists at least one path (may be more) from the start state to some final state that traces out \(w\).
Let \(L_3\) be the language of all strings over \(\Sigma = \{a, b\}\) whose 3rd symbol from the right end is \(a\). Here is an NFA recognizing \(L_3\).
A DFA recognizing \(L_3\) will have to memorize the last 3 symbols seen, i.e., it needs \(2^3\) states (in general, \(|\Sigma|^3\) states).
Exercise. Design a DFA that recognizes \(L_3\).