AlgoPlus//strings / automaton
Read the theory

Finite Automaton Matching

Compile the pattern into a DFA, then each text character is a single state transition.

Shift
Comparisons
Matches
Text
Pattern
Legend
Comparing
Match
Mismatch
AI Tutor Workspace
In a nutshell
This method compiles the pattern into a DFA — a deterministic finite automaton, a little machine with one state for every amount of the pattern matched so far (0 characters, 1, … up to the full pattern). A precomputed table says, for each state and each possible next character, which state to move to. Searching is then just reading the text once, following one transition per character; reaching the final 'accept' state means the pattern was found. Building the table costs O(m × alphabet size), but the scan itself is a single linear pass.
Ready
Press play to begin the cinematic walkthrough.
Bake the pattern into a state machine: each state is 'how much matched so far'. Then matching is just following one arrow per character.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Finite Automaton Matching.