Recall warm-up
- What is L* for L = ∅?
Stuck? Peek at 0.3.3 Operations on languages
- L₁L₂ = {xy}; L{ε} = L; L∅ = ∅; not commutative.
- L⁰ = {ε}; L* = ⋃Lⁿ (n≥0); L⁺ = LL*; L* = L⁺ ∪ {ε}; (L*)* = L*.
- ∅* = {ε} = {ε}*; ∅⁺ = ∅.
- L̅ = Σ* − L (include ε!). (L₁L₂)ᴿ = L₂ᴿL₁ᴿ.
- Counting: C(n,r); fixed positions 2^(free); inclusion–exclusion; complement counting.
- Moore machine output length for input length n?
Stuck? Peek at 1.4 Mealy and Moore machines
- Moore: λ : Q → Δ; output length n+1. Mealy: λ : Q × Σ → Δ; output length n.
- Moore → Mealy: same states, λ'(q,a) = λ(δ(q,a)). Mealy → Moore: ≤ |Q|·|Δ| states.
- No accepting states; equivalence ignores Moore’s first output.
- What does Myhill–Nerode say about aⁿbⁿ?
Stuck? Peek at 1.3.3 Myhill–Nerode theorem
- x ≡_L y ⇔ ∀z: xz ∈ L ⇔ yz ∈ L. Right-invariant equivalence.
- L regular ⇔ finite index; index = #states of minimal DFA (incl. dead class).
- Infinitely many pairwise distinguishable strings ⇒ not regular. aⁿbⁿ: strings aⁱ separated by bⁱ.
The Hook
You type *.pdf to find files, or a pattern like [0-9]+ in a search box. You are describing a whole language with a tiny formula. In TOC that formula is a regular expression (regex). It describes the same languages DFAs accept — but instead of a machine that checks strings, it is a recipe that builds them. GATE asks you to read, write and compare regexes in nearly every paper.
Predict First
Using only “or”, “followed by” and “repeat any number of times”, can you describe the language “all strings over {a, b} that end with b”?
Core Concept
Prediction check
Yes: “(a or b), repeated any number of times, followed by b” — written (a + b)*b. Anything, then a final b.
Building blocks
- ∅ is a regex; L(∅) = ∅ (no strings).
- ε is a regex; L(ε) = {ε}.
- Each symbol a ∈ Σ is a regex; L(a) = {a}.
- If r, s are regexes, so are: r + s (union, L(r) ∪ L(s)); rs (concatenation, L(r)L(s)); r* (Kleene star, L(r)*); and (r) (grouping).
GATE writes union as +; many books and tools write | or ∪. Same meaning. r⁺ is shorthand for rr* (one or more).
Precedence
Like × before + in arithmetic: star binds tightest, then concatenation, then union.
- ab* means a(b*) — not (ab)*.
- a + bc means a + (bc) — not (a+b)c.
- a + b* means a + (b*).
Reading a regex in plain English
Translate piece by piece:
- (a + b)* — “any string over {a,b}”, i.e. Σ*.
- (a + b)*abb — “ends with abb”.
- a(a + b)* — “starts with a”.
- (a + b)*aa(a + b)* — “contains aa”.
- ((a + b)(a + b))* — “even length”.
- b*ab*ab* — “exactly two a’s”.
- (a + ε)(b + ab)* — no two a’s in a row (see 2.1.2).
| regex | in plain English | shortest strings |
|---|---|---|
| (a+b)*abb | ends with abb | abb, aabb, babb |
| a(a+b)* | starts with a | a, aa, ab |
| (a+b)*aa(a+b)* | contains aa | aa, aaa, baa |
| ((a+b)(a+b))* | even length | ε, aa, ab |
| b*ab*ab* | exactly two a’s | aa, aab, aba |
Regex = regular language
Kleene’s theorem: a language is regular (accepted by some DFA) if and only if some regular expression describes it. Chapter 2.2 proves both directions by conversions. So regexes, DFAs, NFAs and ε-NFAs are four faces of one family.
Putting it together
- A regex is built from ∅, ε, symbols with +, concatenation and *.
- Precedence: star, then concatenation, then union.
- Regexes describe exactly the regular languages (Kleene).
Visual
parse tree of a + b c* (star, then concat, then union)
+
/ \
a · L = {a} ∪ {b, bc, bcc, bccc, ...}
/ \
b *
|
c
regex plain English shortest strings
(a+b)*b ends with b b, ab, bb
a(a+b)*b starts with a and ends with b ab, aab, abb
(ab)* ab repeated ε, ab, abab
a*b* some a's then some b's ε, a, b, aa, ab
(a*b*)* anything = (a+b)*Worked Examples
List all strings of length ≤ 3 in L(a*b).
Show the full solution
b, ab, aab. (Every string is some a’s then exactly one b.)
Describe L((a + b)*a(a + b)) in English and give the shortest strings.
Show the full solution
Any string, then a, then exactly one more symbol: the second symbol from the end is a. Shortest: aa, ab.
Which strings are in L(1*(0 + 10)*)? Test 0110, 1100, 10010.
Show the full solution
Read it: some 1s, then blocks that are either “0” or “10”. After the leading 1s, every 1 must be immediately followed by 0 — so “11” can only appear at the very start. 0110: 1*=ε, then 0, then “11” is not a block ⇒ no. 1100: 1*=11, then 0, 0 ⇒ yes. 10010: 1*=1, then 0, 0, then 10 ⇒ yes.
GATE Traps
- ab* ≠ (ab)*: star applies only to the symbol or group directly before it.
- ε and ∅ are different regexes: L(ε) = {ε}, L(∅) = ∅.
- + means union here, not “one or more”; r⁺ (superscript) means one or more.
- a* includes ε — “some a’s” can mean zero a’s.
Memory Hook
Precedence = “Star, String, Sum” (*, concatenation, +) — the order you’d tighten bolts: smallest first.
Connect the Dots
We can read regexes. Next: writing them from descriptions, the identities that simplify them, and the classic GATE task — deciding whether two different-looking regexes describe the same language.
Self-Test
- MCQ
Which string is NOT in L(a(a + b)*b)?
- ab
- aab
- abab
- aba
- MCQ
How is a + bc* parsed?
- ((a + b)c)*
- a + (b(c*))
- (a + b)(c*)
- (a + bc)*
- NAT
How many strings of length 3 are in L((a + b)*a(a + b)(a + b))?
Write your answer before opening the key.
- MSQ
Which regexes describe exactly the strings over {a,b} of even length?
- ((a + b)(a + b))*
- (aa + ab + ba + bb)*
- (a + b)*(a + b)*
- (a + b)(a + b)*
- MCQ
L(∅*) is:
- ∅
- {ε}
- Σ*
- undefined
Rule Card
- Atoms ∅, ε, a; operators r + s (∪), rs (concat), r* (star); r⁺ = rr*.
- Precedence: * > concatenation > +.
- Kleene: regular ⇔ described by a regex.
- Patterns: Σ* = (a+b)*; ends w = (a+b)*w; starts w = w(a+b)*; contains w = (a+b)*w(a+b)*; even length = ((a+b)(a+b))*; exactly two a’s = b*ab*ab*.
Concept Ledger
- regular expression (regex)
- L(r)
- union r + s
- concatenation rs
- Kleene star r*, r⁺
- precedence (* > concat > +)
- Kleene’s theorem (regex ⇔ regular)
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- {ε}.
- n + 1.
- Infinitely many classes (aⁱ separated by bⁱ), so it is not regular.
Self-test answers
- D — Must start with a and end with b.
- A: Fits: a·ε·b.
- B: Fits.
- C: Fits.
- B — Star, then concatenation, then union.
- A: Wrong grouping.
- C: Union binds loosest.
- D: Star applies only to c.
- 4 — Third from the end is a: first symbol a, the other two free: 2² = 4.
- AB — Both repeat 2-symbol blocks.
- C: That is Σ*.
- D: That is Σ⁺.
- B — Star of anything contains ε.
- A: Star always contains ε.
- C: Nothing to repeat.
- D: Defined.
Flashcards
- Regex precedence order?
Reveal answer
Star, then concatenation, then union. - Regex for “ends with abb” over {a,b}?
Reveal answer
(a+b)*abb - Regex for “exactly two a’s” over {a,b}?
Reveal answer
b*ab*ab* - Kleene’s theorem?
Reveal answer
A language is regular iff some regular expression describes it.