Mathwords logoMathwords

Deterministic Finite Automaton — Definition, Formula & Example

A deterministic finite automaton (DFA) is an abstract machine that reads a string one symbol at a time, moving between a fixed, finite set of states. At the end, it either accepts or rejects the string. From any state, each input symbol sends the machine to exactly one next state, so the same string always follows the same path.

A DFA is a 5-tuple M=(Q,Σ,δ,q0,F)M = (Q, \Sigma, \delta, q_0, F). Here QQ is a finite set of states, Σ\Sigma is a finite input alphabet, δ:Q×Σ→Q\delta: Q \times \Sigma \to Q is a total transition function, q0∈Qq_0 \in Q is the start state, and F⊆QF \subseteq Q is the set of accepting states. MM accepts a string w=a1a2⋯anw = a_1 a_2 \cdots a_n if there is a sequence of states r0,r1,…,rnr_0, r_1, \ldots, r_n with r0=q0r_0 = q_0, ri=δ(ri−1,ai)r_{i} = \delta(r_{i-1}, a_{i}) for i=1,…,ni = 1, \ldots, n, and rn∈Fr_n \in F. The set of all strings MM accepts is its language L(M)L(M).

Key Formula

M=(Q, Σ, δ, q0, F),δ:Q×Σ→QM = (Q,\, \Sigma,\, \delta,\, q_0,\, F), \qquad \delta: Q \times \Sigma \to Q
Where:
  • QQ = Finite set of states
  • Σ\Sigma = Finite input alphabet, such as {0,1}\{0, 1\}
  • δ\delta = Transition function: gives exactly one next state for each (state, symbol) pair
  • q0q_0 = Start state, where every computation begins
  • FF = Set of accepting (final) states

Worked Example

Problem: A DFA over Σ={0,1}\Sigma = \{0, 1\} has states q0,q1,q2q_0, q_1, q_2, start state q0q_0, and accepting set F={q0}F = \{q_0\}. It reads a binary number left to right. State qrq_r means the bits read so far have remainder rr when divided by 3, so the transition rule is δ(qr,b)=q(2r+b) mod 3\delta(q_r, b) = q_{(2r + b) \bmod 3}. Does the DFA accept the string 1101?
Step 1: Start in q0q_0 and apply the transition rule to each bit in order. Reading a bit doubles the old value and adds the bit, so the remainder updates as 2r+b2r + b mod 3.
q0→1q(0+1) mod 3=q1→1q(2+1) mod 3=q0q_0 \xrightarrow{1} q_{(0+1) \bmod 3} = q_1 \xrightarrow{1} q_{(2+1) \bmod 3} = q_0
Step 2: Continue with the last two bits, 0 and then 1.
q0→0q(0+0) mod 3=q0→1q(0+1) mod 3=q1q_0 \xrightarrow{0} q_{(0+0) \bmod 3} = q_0 \xrightarrow{1} q_{(0+1) \bmod 3} = q_1
Step 3: The input is used up and the machine stops in q1q_1. Since q1∉Fq_1 \notin F, the string is rejected. Check: 1101 in binary is 13, and 13 leaves remainder 1 when divided by 3, which matches the final state.
11012=8+4+0+1=13,13 mod 3=11101_2 = 8 + 4 + 0 + 1 = 13, \qquad 13 \bmod 3 = 1
Answer: The DFA ends in q1q_1, a non-accepting state, so it rejects 1101. This is correct, because 13 is not divisible by 3. The machine never stores the whole number. Its current state records only the remainder so far.

Why It Matters

DFAs are a core topic in a college Theory of Computation course. Kleene's theorem shows that they recognize exactly the regular languages, the same languages that regular expressions describe. Compilers use DFAs in their lexical analyzers to split source code into tokens. Text-search tools and network protocol checkers also use DFA-based pattern matching.

Common Mistakes

Mistake: Drawing a DFA where some state has no arrow for a symbol, or has two arrows labeled with the same symbol.
Correction: In a DFA, δ\delta is a total function. Every state needs exactly one outgoing transition for each symbol in Σ\Sigma. If a symbol should lead to failure, send it to a non-accepting trap state that loops to itself. A diagram with missing or duplicate arrows describes a nondeterministic automaton (NFA) instead.

Related Terms

  • Discrete Mathematics — Course area where automata and formal languages are taught
  • Deterministic — Explains why each input fixes one unique computation path
  • Finite — Describes the limited state set that bounds a DFA's memory
  • Discrete — DFAs move in separate steps between distinct states