Automata and regular languages
도입됨
5:58
계산 이론 및 컴파일러
This course asks what machines can decide, and how text becomes meaning. The first three units are theory: automata and regular languages, context-free…
영어 내레이션 · 영어와 중국어 자막 전환 가능
이 수업의 내용
| English | 의미 |
|---|---|
| deterministic finite automaton/dɪˌtɜːmɪˈnɪstɪk ˈfaɪnaɪt ɔːˈtɒmətn/ | 결정유한자동기 |
| pumping lemma/ˈpʌmpɪŋ ˈlemə/ | 펌핑 lemma |
| Regular languages/ˈreɡjʊlə ˈlæŋɡwɪdʒɪz/ | languages that a finite automaton or a regular expression can describe |
| nondeterministic finite automaton/ˌnɒndɪˌtɜːmɪˈnɪstɪk ˈfaɪnaɪt ɔːˈtɒmətn/ | a finite automaton that may have several possible moves, or none, for a symbol |
| subset construction/ˈsʌbset kənˈstrʌkʃn/ | turning an NFA into an equivalent DFA whose states are sets of NFA states |
| closed/kləʊzd/ | of a class of languages: applying an operation such as union or complement to members always gives another member |
| product construction/ˈprɒdʌkt kənˈstrʌkʃn/ | building one automaton whose states are pairs of states of two automata, so it runs both at once |
| accepting state |
The table machine
- A deterministic finite automaton 确定有限自动机 (DFA) is a set of states plus a transition table. It reads a symbol, moves to the next state, and at the end of the input it accepts or rejects.
- The course DFA accepts strings over $\{a, b\}$ that end in $ab$.

The course DFA on input aba ends in state —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
q0-a-q1, q1-b-q2, q2-a-q1: ends q1, rejected (q2 accepts, not q1).
The pumping limit
- The pumping lemma 泵引理: any long accepted string splits as $xyz$ with $|xy| \le p$ and $|y| \ge 1$, and every $xy^iz$ is also accepted. So $L = \{a^n b^n\}$ is not regular: pump $y$ (all $a$'s) and the counts no longer match.
- Regular languages 正则语言 cannot count without limit. A finite memory is their ceiling.
The pumping lemma shows a^n b^n is not regular because —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
y lies in the a-block; pumping changes the count of a without b.
A DFA with enough states can recognise $\{a^n b^n : n \ge 0\}$.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
The pumping lemma breaks it: pumping $y$ inside the first $p$ letters adds $a$s only, giving a string with more $a$s than $b$s. A finite machine cannot count without bound.
Traces, exactly
aababgoes q0→q1 (a), q1→q1 (a), q1→q2 (b), q2→q1 (a), q1→q2 (b): accept.abagoes q0, q1, q2, q1: reject, because it ends in the middle of the pattern.- The regular expression
ab|baas a nondeterministic finite automaton 非确定有限自动机 (NFA) guesses which branch to take. The DFA built from it follows both possibilities at once, and this can make the number of states grow a lot.
The trace of aabab in the ends-in-ab DFA is —
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
a:q1, a:q1, b:q2, a:q1, b:q2 - accept.
From NFA to DFA
- The NFA for $(a|b)^*ab$ has three states: $q_0$ loops on $a$ and $b$, $q_0 \xrightarrow{a} q_1$, $q_1 \xrightarrow{b} q_2$.
- The subset construction 子集构造 makes each DFA state a set of NFA states: $\{q_0\} \xrightarrow{a} \{q_0, q_1\} \xrightarrow{b} \{q_0, q_2\}$, which accepts. Only $3$ subsets can be reached.
- In the worst case an NFA with $n$ states needs $2^n$ DFA states: "the third symbol from the end is $a$" takes $4$ NFA states but $8$ DFA states. NFAs are compact to write; DFAs are fast to run, with one table lookup per symbol.
At most how many states can the subset construction produce from a 5-state NFA?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Each DFA state is a subset of the 5 NFA states: 2^5 = 32.
In the DFA for $(a|b)^*ab$, which subset is reached after reading ab?
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
a takes {q0} to {q0, q1}; b then takes it to {q0, q2}, which contains the accepting q2.
Two machines run as one
- Regular languages are closed 封闭 under union, intersection and complement. For the intersection, the product construction 乘积构造 runs both DFAs at once: a state is a pair, one state from each machine, so a 3-state and a 4-state DFA give $3 \times 4 = \mathbf{12}$ states.
- Accept when both parts accept (intersection) or when either does (union). For the complement, swap the accepting and non-accepting states of a complete DFA.
Product construction for the intersection of a 3-state DFA and a 4-state DFA: number of states?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
One state per pair: $3 \times 4$.
The complement of a regular language is regular.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
Swap accepting and non-accepting states of a complete DFA.
Worked example: binary numbers divisible by 3
- Let the state be the remainder so far. Reading bit $b$ turns remainder $r$ into $(2r + b) \bmod 3$, so three states are enough, and remainder 0 is the accepting state 接受状态.
- For 110 (six): 0 → 1 → $(2 + 1) \bmod 3 = 0$ → $0$: accept. For 101 (five): 0 → 1 → 2 → $(4 + 1) \bmod 3 = \mathbf{2}$: reject. A DFA remembers only what the rest of the input needs.
The divisible-by-3 DFA reads the binary string 101. Which remainder state does it end in?
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
$0 \to 1 \to 2 \to (2 \cdot 2 + 1) \bmod 3 = 2$.
Marks that slip away
- Using the pumping lemma to prove regularity. It can only show that a language is not regular.
- Deciding in the middle of the string. Accept or reject only at the end of the input:
abapasses through q2 but ends in q1. - Assuming the DFA is as small as the NFA. The subset construction 子集构造 can need up to $2^k$ states for a $k$-state NFA.
Recap
- A DFA reads one symbol per move and accepts by its final state.
- The pumping lemma shows $\{a^n b^n\}$ is not regular: finite automata cannot count without limit.
- The subset construction 子集构造 turns any NFA into a DFA, with at worst $2^n$ states.
| NFA | DFA | |
|---|---|---|
| Moves on a symbol | to any of several states | to exactly one state |
| Size | small, easy to write | up to $2^n$ states |
| Running | track a set of states | one table lookup per symbol |
어떤 문제가 있었나요? 사이트 팀만 이 내용을 볼 수 있습니다.