CS 181 Lecture 9 -- Fall 2026, UCLA
Overview
Eli Jaffe develops Kleene’s theorem by showing how to construct an NFA for a regular expression using base cases and the operations for concatenation, alternation, and Kleene star. He explains how compiling an NFA into a DFA can make repeated matching against long inputs, such as DNA sequences, more efficient, then contrasts regular languages with counting problems such as majority and equal numbers of zeros and ones.
Key takeaways
- A regex of size m can be converted inductively into an equivalent NFA with O(m) states by handling base expressions and composing machines for concatenation, OR, and Kleene star.
- Direct NFA simulation takes O(nm) time for an input of length n and regex size m, while compiling to a DFA can cost up to 2^m states but then allows O(n) matching per input.
- DFA compilation is useful when a compact regex is reused on very long inputs, such as checking a DNA pattern against a genome of roughly 10^10 symbols or screening many genomes for the same pattern.
- The majority function and the language of strings with equal numbers of 0s and 1s are not regular because they require tracking counts that can grow with input length.
- Equal counts of substrings 01 and 10 do not require unbounded counting: for nonempty binary strings, the counts are equal exactly when the first and last bits match.
- The pumping lemma says every sufficiently long accepted string in a regular language has a nonempty segment that can be repeated any number of times, including zero, while preserving acceptance.
Chapters
- Eli Jaffe reviews the previous lecture’s DFA and NFA equivalence, closure properties, and introduction to regular expressions.
- The lecture plan covers regex examples, Kleene’s theorem, and the grep pattern-matching tool.
- Jaffe says exam 1 sample solutions and previous-year exam 2 materials are available on EdStem, and gives expected grading timelines for homework 2 and exams.
- The regex definition uses base expressions for 0, 1, epsilon, and the empty language, then builds larger expressions with concatenation, OR, and Kleene star.
- A recording interruption obscures several examples; Jaffe later says the missing material covered checking whether strings match regular expressions.
- The lecture resumes by formalizing the function and language recognized by a regular expression.
- For a regular expression R, Jaffe defines a Boolean function F_R that outputs 1 exactly when input string X matches R.
- The corresponding language L_R is the set of all strings that match R.
- A function is regular if some regular expression computes it, paralleling definitions of functions computed by DFAs, NFAs, and Boolean circuits.
- Strings with a number of 1s divisible by three can be described by repeating groups containing three 1s with arbitrary runs of 0s between them.
- Strings whose fourth bit from the end is 1 use an arbitrary binary prefix, then 1, then exactly three arbitrary bits.
- Strings containing 101 or 010 as a substring use an arbitrary binary prefix and suffix around either target pattern.
- Kleene’s theorem states that regular expressions and DFAs recognize the same languages.
- The equivalence requires both converting any regex into an equivalent DFA and converting any DFA into an equivalent regex.
- Jaffe focuses first on constructing an NFA from a regex, then uses the established equivalence between NFAs and DFAs.
- For a regex R of size m, the construction produces an equivalent NFA with O(m) states.
- The NFA acts as an intermediate representation: once it exists, the known NFA-to-DFA conversion completes the route to a DFA.
- The construction’s linear state count matters for practical applications as well as for proving equivalence.
- Simulating an NFA with O(m) states on an input of length n takes O(nm) time in the approach discussed.
- The NFA construction alone does not improve the naive matching bound, because the machine must still be evaluated across the whole input.
- Jaffe uses this limitation to motivate a compiled-DFA strategy for patterns that will be reused.
- The lecture describes grep as generalized regular-expression processing and relates its matching strategy to automata.
- After constructing the regex’s NFA, converting it to a DFA can yield up to 2^m states.
- The compiled DFA processes each input symbol with a single state transition, giving O(n) matching time after preprocessing.
- The discussed total cost is O(n + 2^m), compared with O(nm) for direct NFA simulation, where n is input length and m is regex size.
- A human genome is used as an example of a very long input, around 10^10 symbols, matched against a compact pattern of size about 10.
- If the same pattern is tested against many inputs, the DFA can be built once and reused, amortizing its exponential preprocessing cost.
- Jaffe leverages the inductive definition of regexes: establish NFAs for the base expressions, then show how to combine them.
- The base NFAs accept exactly 0, exactly 1, the empty string for epsilon, or no strings for the empty language.
- Proving the base cases and the three construction steps completes the inductive argument.
- For concatenation, epsilon transitions connect accepting states of the first NFA to the start state of the second.
- For OR, a new start state branches by epsilon transitions to the start states of both NFAs.
- For Kleene star, epsilon transitions loop from accepting states back to the start; an additional start-and-accept state enables the empty string.
- Jaffe parses the example regex as 0 concatenated with the Kleene star of 100 OR 01.
- The component NFAs for 100 and 01 are combined with an OR construction, then connected into a Kleene-star loop.
- The diagram illustrates the inductive method, not an optimized automaton; equivalent NFAs may be simplified.
- Negating an NFA or regex is less direct than concatenation, OR, or Kleene star, echoing the difficulty of complementing an NFA.
- The route through an NFA and DFA allows complementing the language using the simpler DFA operation of swapping accepting and rejecting states.
- Jaffe notes that the lecture has sketched regex-to-NFA construction; the reverse direction can also be shown, though it is not developed here.
- A student asks why there are only countably many DFAs and NFAs; Jaffe agrees that the claim needs a more precise follow-up discussion.
- The lecture summarizes that DFAs, NFAs, and regular expressions compute the same class of functions.
- These models support unbounded-length inputs and illustrate how intermediate representations can connect computational models.
- Majority outputs 1 when a bit string contains at least as many 1s as 0s, with ties accepted.
- Jaffe argues that majority is not regular because deciding it appears to require tracking an unbounded difference between counts.
- The example raises the central question of which functions finite automata can and cannot compute.
- EQ accepts strings with equal numbers of 0s and 1s; Jaffe explains why remembering those counts requires more than a fixed finite-state machine.
- EEQ asks whether a string contains equal numbers of substrings 01 and 10, and is regular despite appearing to involve counting.
- For nonempty strings, the counts of 01 and 10 are equal exactly when the first and last bits match, a property a DFA can track.
- Jaffe introduces the pumping lemma and the Myhill-Nerode theorem as tools for proving that a language is not regular.
- The Myhill-Nerode theorem is stronger: it characterizes regularity and can determine the minimum number of states needed by a DFA.
- The pumping lemma can show nonregularity for some languages but cannot prove every nonregular language is nonregular.
- Showing that a model cannot compute a function requires ruling out every possible machine, unlike demonstrating one construction that works.
- Jaffe compares the strategy to proving AND-OR circuits are not universal by identifying monotonicity, a property shared by those circuits but not by all Boolean functions.
- The pumping lemma will similarly identify a property shared by every regular function and violated by examples such as majority.
- For a regular function, there is a pumping length P such that every accepted string X of length at least P can be split into A, B, and C.
- The decomposition must satisfy |B| > 0 and |AB| <= P.
- For every integer i >= 0, the string AB^iC must also be accepted, including the versions with B removed or repeated many times.
- The pumping lemma requires a suitable decomposition for each sufficiently long accepted string, not for every arbitrary split.
- Jaffe emphasizes that preserving acceptance while inserting or removing arbitrarily many copies of a nonempty B is a restrictive property.
- The lecture ends with the pumping lemma’s statement; the next class will apply it to determine nonregularity.
Transcript excerpt
0:03 All right. We are recording. Hello everybody. Happy the farthest you will be away from another exam for the rest of the quarter. Congratulations. Hopefully it wasn't too painful. Um I guess a couple Well, let's talk about what we did last class and then I'll do the logistical updates. Reminder, I know it's been a while. It's been like a week since we've actually talked about stuff. We're sort of in the tail end of wrapping up our discussion of finite automata. Uh and so what we did last class uh pretty much was we finished off our discussion of DFAs versus NFAs. We did a like
0:51 pros and cons list. Talked about the relationships a little bit. After our big result that, you know, they're actually equivalent in computational power, which was pretty cool. Uh and we talked about the relationships between all these closure properties. And what we started to introduce as a sort of accumulation of this DFA stuff was regular expressions. And we just barely got to a formal definition of regular expressions. We talked a little bit about the connection between regular expressions and Oop.
1:39 No, no, no. Don't do that. Oh, no. Uh Let me see if I can delay that. Hold on, 1 second. Uh Can I schedule it? Schedule restart. Today Oh, no, it won't let me. Um I I guess we'll deal with that when it happens. Uh well, such is life. Such is life. Uh we talked a little bit about the relationship between regular expressions and NFAs and DFAs. Kind of
2:28 looking at these applications, saying we would love a one-pass algorithm for something like string matching instead of this sliding window approach. Uh and I tantalized you with this idea that we could actually do it by exploring the
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Eli Jaffe.