You are about to send money from bKash. You type the number, 01712345678, and before you touch the Send button the form has already made up its mind. Add a twelfth digit and the field turns red. Start the number with 02 and it is rejected. The phone did not look the number up in any database; it only checked the number's shape: eleven digits, the first two being 01, the third a digit from 3 to 9, then eight more of any kind. The code that does this is tiny. It reads the number once, from left to right, and keeps only a few facts in its head: how many digits so far, and whether the first three were acceptable.
The last six chapters taught you to get answers out of data: sort it, search it, find the cheapest route through it. This chapter turns the question around: what can a machine of a given kind solve at all? The first and simplest machine is the one inside that form, a finite automaton, whose whole memory is a fixed handful of states. It is not a new kind of object. It is a graph, circles joined by labelled arrows, like the road maps you walked through with Dijkstra, and running the machine on an input means walking a path through it.
By the end of the chapter you will be able to describe a set of strings with a regular expression and design a finite automaton for it. You will convert between the forms: an NFA into a DFA by the subset construction, a regular expression into an NFA by Thompson's construction, and a DFA back into a regular expression. You will shrink a DFA to its smallest form, use closure properties to build machines from machines, and prove with the pumping lemma that some simple-looking languages, like n zeros followed by n ones, are beyond every finite automaton.