Study guide: Automata
Overview
Finite automata are the simplest model of computation: a machine with finitely many states that reads a string one symbol at a time and finally accepts or rejects. The languages they recognise are the regular languages, the same ones described by regular expressions.
Key ideas explained
Deterministic finite automata
A DFA is a 5-tuple (Q, Σ, δ, q₀, F): states, alphabet, transition function, start state and accepting states. From every state there is exactly one transition for every symbol, and the machine accepts if it ends in a state of F. Missing transitions are usually sent to a dead state.
Nondeterministic automata
An NFA may have several, zero or ε-transitions from a state, and accepts if some path leads to an accepting state. Every NFA can be converted to a DFA by the subset construction (possibly with up to 2ⁿ states), so NFAs are not more powerful, only sometimes more compact.
What regular languages can and cannot do
Regular languages are closed under union, concatenation, star, complement and intersection. The pumping lemma shows that {aⁿbⁿ} is not regular: a machine with finite memory cannot count without bound. That is why regular expressions cannot match balanced parentheses.
Designing a DFA
Decide what the machine must remember. Parity of 1s needs 2 states. “Ends with 01” needs 3, tracking how much of 01 has just been seen. “Divisible by k” needs k states, one for each remainder.
Worked examples
Even number of 1s
Problem. Design a DFA over {0, 1} accepting strings with an even number of 1s, and run 1011 and 1001.
- States E (start, accepting) and O. A 0 keeps the state; a 1 switches it.
- 1011: E → O → O → E → O, which ends in O (three 1s) and is rejected.
- 1001: E → O → O → O → E, which ends in E (two 1s) and is accepted.
Answer. 1011 is rejected and 1001 is accepted.
Strings ending in 01
Problem. Design a DFA for binary strings ending in 01.
- q0: no progress; q1: last symbol was 0; q2 (accepting): last two symbols were 01.
- Transitions: q0 –0→ q1, q0 –1→ q0; q1 –0→ q1, q1 –1→ q2; q2 –0→ q1, q2 –1→ q0.
- Input 1101 ends in q2 (accepted); input 0100 ends in q1 (rejected).
Answer. The three-state DFA above accepts exactly the strings that end in 01.
Enter these same values in the calculator above and compare each step with the working shown here.
Common mistakes to avoid
- Leaving out a transition for some symbol in a DFA.
- Marking the wrong states as accepting. If the start state is accepting, the empty string is accepted.
- Believing NFAs recognise more languages than DFAs.
- Forgetting to consider the empty string.
- Expecting a finite automaton to recognise balanced parentheses or aⁿbⁿ.
Where this shows up in computer science
- Lexical analysis in compilers and regular-expression engines are based on finite automata.
- Protocols and user interfaces are specified as state machines, for example TCP connection states.
- Hardware sequence detectors and control units are finite-state machines.
Test yourself
Try each question before opening the answer.
What language does a one-state automaton that is both start and accepting, with self-loops on every symbol, accept?
All strings over the alphabet (Σ*).
How many states does a DFA for “contains the substring 11” need?
Three: no progress, seen one 1, and seen 11 (accepting, with loops on both symbols).
What is the fewest states of a DFA over {a} accepting strings whose length is divisible by 3?
Three.