While state diagrams are easy to grasp intuitively, we need a precise, formal definition and good notation to prove theorems about them.
The DFA above has five associated objects that we need to formalize:
How do we formalize the transitions?
All together, we have the definition:
A deterministic finite automaton (DFA) is a 5-tuple \((Q, \Sigma, \delta, s, F)\) where:
True or false:
a DFA must have at least one accept state?
All together, we have the definition:
A deterministic finite automaton (DFA) is a 5-tuple \((Q, \Sigma, \delta, s, F)\) where:
True or false:
every state must have exactly one outbound transition for each symbol in the alphabet?
Note that \(|Q \times \Sigma| = |Q| \cdot |\Sigma|\)
We can formally describe this DFA as \(M_1 = (Q, \Sigma, \delta, q_1, F)\) where:
\(Q = \{q_1, q_2, q_3\}\)
\(\Sigma = \{0, 1\}\)
\(\delta\) is defined by the following lookup table:
\(0\) | \(1\) | |
---|---|---|
\(q_1\) | \(q_1\) | \(q_2\) |
\(q_2\) | \(q_3\) | \(q_2\) |
\(q_3\) | \(q_2\) | \(q_2\) |
\(q_1\) is the start state.
\(F = \{q_2\}\)
1
followed by an even number of 0
s.What is the formal description of this DFA?
\[M_2 = (\fragment{\{q_1, q_2\},} \fragment{\{0, 1\},} \fragment{\delta,} \fragment{q_1,} \fragment{\{q_2\}}),\]
where \(\delta\) is defined by the table:
\(0\) | \(1\) | |
---|---|---|
\(q_1\) | \(q_1\) | \(q_2\) |
\(q_2\) | \(q_1\) | \(q_2\) |
What language does this DFA decide?
What is the formal description of this DFA?
\[M_3 = (\{q_1, q_2\}, \{0, 1\}, \delta, q_1, \{q_1\}),\]
where \(\delta\) is defined by the table:
\(0\) | \(1\) | |
---|---|---|
\(q_1\) | \({q_1}\) | \({q_2}\) |
\(q_2\) | \({q_1}\) | \({q_2}\) |
What language does this DFA recognize?
\[ L(M_3) = \setbuild{w \in \{0, 1\}^*}{w[|w|] = 0} \fragment{\cup \{\emptystring\}} \fragment{= \setcomplement{L(M_2)}} \]
Task: Design a DFA that accepts strings of symbol \(\string{a}\) whose length is a multiple of 3.
\[ \setbuild{\string{a}^{3n}}{n \in \N} = \setbuild{w \in \{\string{a} \}^*}{|w| \text{ is a multiple of 3}} = \string{\{\emptystring, aaa, aaaaaa, \ldots\}} \]
Task: Design a DFA that accepts strings of symbol \(\string{a}\) whose length is of the form \(3n + 2\)
\[ \setbuild{\string{a}^{3n + 2}}{n \in \N} = \setbuild{w \in \{\string{a} \}^*}{|w| \equiv 2 \mod 3} = \string{\{aa, aaaaa, \ldots\}} \]
Task: Design a DFA that accepts binary strings that represent an even number.
\[ \setbuild{w \in \{0, 1\}^*}{w \text{ represents a multiple of 2 in binary}} \]
We’ve already done this! Which of the following is it?
Binary numbers are even if and only if they end in 0.
Task: Design a DFA that accepts binary strings that represent a multiple of 3.
\(0\) | \(1\) | |
---|---|---|
\(q_0\) | \(\fragment{q_0}\) | \(\fragment{q_1}\) |
\(q_1\) | \(\fragment{q_2}\) | \(\fragment{q_0}\) |
\(q_2\) | \(\fragment{q_1}\) | \(\fragment{q_2}\) |
Task: Design a DFA that accepts binary strings that contain the substring \(\string{001}\).
What do we need to keep track of? Which parts of this substring have we seen so far?
What states do we need?
What are the transitions?
\(0\) | \(1\) | |
---|---|---|
$q $ | \(\fragment{q_0}\) | \(\fragment{q }\) |
$q_0 $ | \(\fragment{q_{00}}\) | \(\fragment{q }\) |
$q_{00} $ | \(\fragment{q_{00}}\) | \(\fragment{q_{001}}\) |
$q_{001} $ | \(\fragment{q_{001}}\) | \(\fragment{q_{001}}\) |
Task: Design a DFA that accepts strings that are in a given dictionary (finite list of words).
Solution: Build a trie (prefix tree) data structure!
(With some minor modifications to satisfy the formal definition of a DFA.)
The finite automaton \(M = (Q, \Sigma, \delta, s, F)\) accepts a string \(w = w_1 w_2 \ldots w_n \in \Sigma^n\) if there exists a sequence of states \(r_0, r_1, \ldots, r_n \in Q\) such that:
\(M\) decides a language \(A\) (denoted \(L(M) = A\)) if \(A = \setbuild{w \in \Sigma^*}{M \text{ accepts } w}\).
A language/decision problem \(A\) is DFA-decidable if there exists a DFA \(M\) such that \(L(M) = A\). Equivalently: if it uses a constant amount of memory and runs in exactly \(n\) steps on inputs \(w \in \Sigma^n\).
\(0\) | \(1\) | |
---|---|---|
\(q_1\) | \(q_1\) | \(q_2\) |
\(q_2\) | \(q_3\) | \(q_2\) |
\(q_3\) | \(q_2\) | \(q_2\) |
According to the formal definition of computation, this DFA accepts the string \(w = \string{0100100}\) because the sequence of states it enters when processing this string is: \[ (r_0, r_1, r_2, r_3, r_4, r_5, r_6, r_7) = (q_1, q_1, q_2, q_3, q_2, q_2, q_3, q_2) \] which satisfies the three conditions: