Deterministic Finite Automata (DFA)

the finite-memory limit of a DFA

The deepest thing a beginner must internalise about DFAs is what they cannot do, and why. A DFA has only finitely many states, and a state is its entire memory. So a DFA can remember only a bounded amount of information — it can count up to some fixed limit, or track a remainder, or remember the last few symbols, but it cannot keep an unbounded running tally. There is simply nowhere to put a number that grows without end.

The cleanest illustration is matching brackets, or its stripped-down cousin the language { a^n b^n : n >= 0 } (n a-s followed by exactly n b-s). To accept it, a machine reading the b-s would have to recall how many a-s came before — and n can be arbitrarily large. With only, say, 100 states, the machine cannot tell apart a^100 from a^101 by the time the b-s arrive: by the pigeonhole principle two different a-counts must funnel into the same state, after which the machine behaves identically and is forced to accept or reject both alike, so it must get one of them wrong. Hence no DFA recognises a^n b^n; this language is not regular.

This is not a defect to be patched but the defining boundary of the model. Recognising balanced brackets to arbitrary depth needs a memory that can grow with the input — exactly what a stack provides, which is why the next, stronger model (the pushdown automaton) adds one. Internalising 'a DFA cannot count without bound' tells you, before you waste time, when a problem is beyond finite-state machines and which tool to reach for instead.

Try to build a DFA for balanced parentheses like ((())) over { (, ) }. To know that ))) correctly closes ((( you must have counted three open parens — but the nesting depth can be any number, and a fixed set of states cannot store an arbitrarily large count. No DFA works; a pushdown automaton, which has a stack, can push one marker per ( and pop one per ).

Finite states = bounded memory: a DFA cannot match arbitrarily many opening to closing brackets.

The limit is unbounded counting, not large counting. A DFA can perfectly check 'at most 1000 a-s' (just use enough states); it fails only when the bound itself is allowed to be arbitrary.

Also called
why a DFA cannot countbounded-memory limitation有限記憶限制DFA 不能計數