Theory · Finite Automata

Finite Automata

The simplest possible computer: a handful of states and no memory. Start here to see what "compute" even means.

Theory of Computation Basics → Interview
01

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.

A machine that accepts or rejects strings is a decider for a language — the set of all strings it accepts. Computation theory is really the study of which languages which machines can recognize.
02

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:

even odd start 1 1 0 0

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.

03

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:

Every NFA has an equivalent DFA (subset construction: DFA states = sets of NFA states). Nondeterminism buys convenience, not power — a theme that returns, far less happily, at P vs NP.
04

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).

05

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.

Quick Quiz

1. A finite automaton’s memory is limited to…
2. A double-circle state denotes…
3. NFAs compared to DFAs recognize…
4. Which language is NOT regular?
5. The pumping lemma is used to prove a language is…