A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Regular Expressions and Languages

College Depth 83 in the knowledge graph I know this Set as goal
199topics build on this
468prerequisites beneath it
See this on the map →
Nondeterministic Finite AutomataContext-Free GrammarsPost Correspondence Problem
regular-languages automata formal-languages

Core Idea

Regular expressions are a compact algebraic notation for describing regular languages using concatenation, union, and Kleene star. Kleene's theorem establishes that the languages described by regular expressions are exactly those recognized by finite automata — every regex can be converted to an NFA, and every DFA can be converted to a regex. The pumping lemma for regular languages provides a tool for proving that certain languages (e.g., {an bn}) are not regular, by showing that sufficiently long strings in the language must contain a pumpable substring.

How It's Best Learned

Practice converting between the three representations: regex to NFA (Thompson's construction), NFA to DFA (subset construction), and DFA to regex (state elimination). Then use the pumping lemma to prove specific languages are not regular — this sharpens understanding of what finite memory cannot achieve.

Common Misconceptions

Explainer

You have studied nondeterministic finite automata (NFAs), so you know what a regular language is: a language accepted by some finite automaton, deterministic or nondeterministic. Regular expressions give you a completely different notation for exactly the same class of languages — an algebraic description rather than a machine description. Kleene's theorem, the central result here, says these two descriptions are interchangeable.

The syntax of regular expressions builds languages from three operations. Concatenation (AB) means "a string from A followed by a string from B." Union (A|B) means "a string from A or from B." Kleene star (A*) means "zero or more strings from A concatenated together." Starting from single-character base cases (and ∅ and ε), these three operations generate exactly the regular languages. So the expression `a(b|c)*` describes strings starting with 'a' followed by any sequence of 'b's and 'c's — a language you could also describe with a small NFA.

Kleene's theorem formalizes the equivalence. Every regular expression can be converted to an NFA (Thompson's construction builds the NFA inductively over the expression's structure, introducing ε-transitions to combine pieces), and every DFA can be converted back to a regular expression (state elimination removes states one by one, accumulating transitions into regular expression labels). This triangle of conversions — regex ↔ NFA ↔ DFA — means you can choose whichever representation is most convenient: regex for compact human-readable descriptions, NFA for theoretical reasoning about closure properties, DFA for efficient simulation.

The pumping lemma gives you a way to prove that certain languages are *not* regular. The key insight is that any finite automaton has a fixed number of states. If a string is long enough to exceed that count, the automaton must repeat a state while reading it — creating a "loop" in the computation. This loop can be pumped (iterated any number of times) while keeping the result in the same language, because the automaton follows the same path each time around the loop. If a language lacks this pumpable-substring property for sufficiently long strings, no finite automaton can recognize it. The classic example is {an bn : n ≥ 0} — matching that n a's are followed by n b's requires memory that grows with n, which no finite automaton provides. The pumping lemma is a *necessary* condition for regularity, not sufficient: it proves languages are non-regular, but satisfying it doesn't make a language regular.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersDividing IntegersUnit RatesProportionsPercent ConceptConverting Between Fractions, Decimals, and PercentsOperations with Rational NumbersTwo-Step EquationsSolving Multi-Step EquationsEquations with Variables on Both SidesLiteral EquationsSlope-Intercept FormPoint-Slope FormWriting Linear EquationsParallel and Perpendicular Line SlopesGraphing Linear EquationsPiecewise FunctionsStep FunctionsComposition of FunctionsInverse FunctionsRadical Functions and GraphsRational ExponentsExponential Functions and GraphsLogarithms IntroductionBig-O Notation and Asymptotic AnalysisBreadth-First Search (BFS)Shortest Paths in Unweighted GraphsDijkstra's Shortest Path AlgorithmAlgorithm Analysis and Big-O NotationTuring MachinesDeterministic Finite AutomataNondeterministic Finite AutomataRegular Expressions and Languages

Longest path: 84 steps · 468 total prerequisite topics

Prerequisites (1)

Leads To (2)