A DFA can be visually specified by a state diagram:
(A DFA can be seen as a special type of directed graph with labeled edges and nodes.)
Example processing the string 1101:
1101
Begin in the start state \(a\).
Read 1 and transition to state \(b\).
1101
Read 1 and transition to state \(b\).
1101
Read 0 and transition to state \(c\).
1101
Read 1 and transition to state \(b\).
1101
Since the final state \(b\) is an accept state, the DFA accepts the string.
Which string(s) below are accepted by this DFA?
The formal definition of syntax of a model of computation says what an instance of the model is. (Semantics is a formal definition of what the model does; more later.)
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 input alphabet?
Note that \(|Q \times \Sigma| = |Q| \cdot |\Sigma|\)
We can formally describe this DFA as \(M_1 = (Q, \Sigma, \delta, a, F)\) where:
\(Q = \{a, b, c\}\)
\(\Sigma = \{0, 1\}\)
\(\delta\) is defined by the following lookup table:
| \(0\) | \(1\) | |
|---|---|---|
| \(a\) | \(a\) | \(b\) |
| \(b\) | \(c\) | \(b\) |
| \(c\) | \(b\) | \(b\) |
\(a\) is the start state.
\(F = \{b\}\)
1 followed by an even number of 0s.What is the formal description of this DFA?
\[M_2 = (\fragment{\{a, b\},} \fragment{\{0, 1\},} \fragment{\delta,} \fragment{a,} \fragment{\{b\}}),\]
where \(\delta\) is defined by the table:
| \(0\) | \(1\) | |
|---|---|---|
| \(a\) | \(a\) | \(b\) |
| \(b\) | \(a\) | \(b\) |
What language does this DFA decide?
What is the formal description of this DFA?
\[M_3 = (\{a, b\}, \{0, 1\}, \delta, a, \{a\}),\]
where \(\delta\) is defined by the table:
| \(0\) | \(1\) | |
|---|---|---|
| \(a\) | \(a\) | \(b\) |
| \(b\) | \(a\) | \(b\) |
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 finite language.
Solution: Build a trie (prefix tree) data structure!
Example: \(A = \string{\{0, 000, 001, 1001, 1010, 10010\}}\)
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 is 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 is 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\) | |
|---|---|---|
| \(a\) | \(a\) | \(b\) |
| \(b\) | \(c\) | \(b\) |
| \(c\) | \(b\) | \(b\) |
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) = (a, a, b, c, b, b, c, b) \] which satisfies the three conditions: