Finite Automata
The simplest possible computer: a handful of states and no memory. Start here to see what "compute" even means.
A Machine With Only States
A finite automaton (or state machine) is the most stripped-down model of computation: a finite set of states, a start state, some accepting states, and transitions that move between states as it reads input one symbol at a time. No memory beyond the current state. When the input ends, it either sits in an accepting state (accept) or not (reject).
That’s it — and yet it models turnstiles, traffic lights, regex engines, TCP connection state, and vending machines. Anything that reacts to a stream of events with a bounded set of situations is a state machine.
DFA — One Path, No Choices
A Deterministic Finite Automaton has exactly one transition per (state, symbol). Given an input, its path is fully determined. Here’s a DFA accepting binary strings with an even number of 1s:
Double circle = accepting. Start in even; each 1 flips even⇄odd, each 0 stays. End in even → accept. Two states, zero memory, and it counts parity of arbitrarily long input.
NFA — Many Paths at Once
A Nondeterministic Finite Automaton may have several transitions for the same symbol (or none, or ε-moves that consume nothing). It accepts if any path leads to an accepting state. NFAs are often far easier to design — “guess and check” — yet no more powerful:
What Finite Automata Cannot Do
The catch: no memory. A DFA can’t count without bound. It cannot recognize aⁿbⁿ (n a’s then n b’s) because it would need to remember n, and n is unbounded while states are finite. This limit is provable — the pumping lemma: any sufficiently long accepted string has a middle section you can repeat (“pump”) and still be accepted, which aⁿbⁿ can’t survive.
That single limitation — finite memory — is exactly what the next models climb past. Add a stack → pushdown automata (matched brackets). Add an infinite tape → Turing machines (everything).
Interview Questions
What is a finite automaton and what does it recognize?
A machine with finitely many states, a start state, accepting states and transitions on input symbols. It recognizes a regular language — the set of strings that drive it from start to an accepting state, using no memory beyond the current state.
DFA vs NFA — is one more powerful?
No. NFAs allow multiple/ε-transitions and accept if any path accepts, making them easier to design, but subset construction converts any NFA to an equivalent DFA. Same class of languages (regular); nondeterminism only adds convenience.
Why can’t a DFA recognize aⁿbⁿ?
It would need to remember n to match the b’s, but n is unbounded and a DFA has finitely many states. The pumping lemma proves it: long strings must contain a loop you can repeat, which breaks the exact a/b balance.
Give a real system that’s a state machine.
TCP connection states (LISTEN, SYN_SENT, ESTABLISHED, …), a regex matcher, a UI wizard, a vending machine. Anything with a bounded set of situations reacting to a stream of events.