Recall warm-up
- How is ab* parsed?
Stuck? Peek at 2.1.1 Regular expressions: syntax and meaning
- 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*.
- Minimal DFA for “no two consecutive a’s” has how many states?
Stuck? Peek at 1.3.2 Partition and table-filling methods
- Partition: remove unreachable; P₀ = {F, Q−F}; split by signatures w.r.t. previous partition; stop when stable.
- Table filling: n(n−1)/2 cells; mark (F, non-F); propagate “successor pair marked ⇒ mark”; unmarked = equivalent.
- Count by distinct futures: list situations with different accepted continuations, include dead / satisfied states.
- Exactly k of a symbol: k + 2 states; at least k: k + 1; at most k: k + 2.
- Is the minimal DFA unique?
Stuck? Peek at 1.3.1 Unreachable, equivalent and distinguishable states
- Step 0: delete unreachable states (BFS from q₀).
- p ≡ q ⇔ ∀w: δ̂(p,w) ∈ F ⇔ δ̂(q,w) ∈ F. Distinguishable ⇔ some w separates.
- ≡₀ = {F, Q−F}; ≡ₖ₊₁ splits by where symbols lead w.r.t. ≡ₖ; stop when stable.
- Merge classes → minimal DFA, unique up to renaming.
The Hook
Two programmers write different search patterns for “binary strings without two consecutive 1s”. Are their patterns the same? Testing a few strings proves nothing if they agree; a single disagreement proves they differ. GATE loves this: four regexes, “which ones are equivalent to (a + b)*?”. You need identities for simplification and a fast hunt for counterexamples.
Predict First
Are a*b* and (ab)* the same language? Are (a + b)* and (a*b*)* the same?
Core Concept
Prediction check
a*b* vs (ab)*: different — “aab” ∈ a*b* but ∉ (ab)*. (a+b)* vs (a*b*)*: same — every symbol is itself an a*b* block, and nothing outside Σ* can appear.
| length | (a+b)* | (a*b*)* | a*b* | (ab)* |
|---|---|---|---|---|
| 0 | ε | ε | ε | ε |
| 1 | a, b | a, b | a, b | — |
| 2 | aa ab ba bb | aa ab ba bb | aa ab bb | ab |
Identities to know cold
| Identity | Why |
|---|---|
| ∅ + r = r, ∅r = r∅ = ∅ | ∅ is the zero of concatenation |
| εr = rε = r | ε is the identity |
| ∅* = ε, ε* = ε | star always gives ε |
| r + r = r | union of a set with itself |
| (r*)* = r*, r*r* = r* | repeating repeats adds nothing |
| rr* = r*r = r⁺, r* = ε + rr* | one-or-more plus zero |
| (ε + r)* = r*, (ε + r)r* = r* | ε adds nothing to a star |
| (rs)*r = r(sr)* | shifting identity (rsrs…r = r srsr…) |
| (r + s)* = (r*s*)* = (r* + s*)* = r*(sr*)* = (r*s)*r* | all mean “any mix of r’s and s’s” |
| r(s + t) = rs + rt, (s + t)r = sr + tr | concatenation distributes over union |
Famous non-identities
- (r + s)* ≠ r* + s* (ab is in the left only).
- (rs)* ≠ r*s* (aab separates (ab)* from a*b*).
- (r + s)* ≠ r*s* (ba separates).
- r*s* ≠ (rs)*; (r*s*)* ≠ r*s*.
- rs ≠ sr in general.
| pair | separating string | in which side? |
|---|---|---|
| (r+s)* vs r* + s* | ab | left only |
| (rs)* vs r*s* | aab | right only |
| (a+b)* vs a*b* | ba | left only |
| (a+b)⁺ vs (a+b)* | ε | right only |
Writing regexes from descriptions
- Find the skeleton: what must appear, in what order.
- Fill the gaps with what is allowed between them.
- Test on the shortest strings and on edge cases (ε, single symbols).
- At least one a: (a+b)*a(a+b)* or b*a(a+b)*.
- At most one a: b*(ε + a)b*.
- No two consecutive a’s: (b + ab)*(ε + a) — every a is followed by b except possibly the last.
- Number of a’s divisible by 3: (b*ab*ab*ab*)* + b* → simplifies to b*(ab*ab*ab*)*.
- Starts and ends with different symbols: a(a+b)*b + b(a+b)*a.
Checking equality of two regexes
- Compare the shortest strings of each (ε? length 1? length 2?) — most GATE distractors die here.
- Look for a structural difference: a string one forces (like ab adjacency) the other forbids.
- If you suspect equality, transform one into the other with identities.
- The guaranteed method: build both minimal DFAs and compare (the minimal DFA is unique).
Putting it together
- Learn the identities: ∅* = ε, (r*)* = r*, (r+s)* has many equal forms, (rs)*r = r(sr)*.
- (r+s)* ≠ r* + s* ≠ r*s*; (rs)* ≠ r*s*.
- Compare shortest strings first; one counterexample settles inequality.
Visual
no two consecutive a's: (b + ab)*(ε + a) strings ≤ 3: ε a b ab ba bb aba abb bab bba bbb (11 = 1+2+3+5 Fibonacci-like) check "aab": (b+ab)* can't make "aa" → not in L ✓
States: A, B, D
Transitions: A>A: b; A>B: a; B>A: b; B>D: a; D>D: a,b
equivalence hunt: r1 = (a+b)* r2 = a* + b* length 2: r1 gives aa ab ba bb r2 gives aa bb counterexample "ab" → r1 ≠ r2
Worked Examples
Simplify ε + aa*.
Show the full solution
ε + aa* = ε + a⁺ = a*.
Write a regex for binary strings with an even number of 0s.
Show the full solution
Skeleton: 0s come in pairs, with 1s anywhere: 1*(01*01*)*. Check: ε ✓ (zero 0s), 1 ✓, 00 ✓, 0 ✗, 1010 ✓ (leading 1, then one block 0·1·0·ε).
Which are equal to (a + b)*? (i) (a*b*)* (ii) (a* + b*)* (iii) a*(ba*)* (iv) (ab + b)*a*
Show the full solution
(i) yes, (ii) yes (each single symbol is a block), (iii) yes — the identity (r+s)* = r*(sr*)* with r = a, s = b. (iv) no: blocks ab and b can never produce “aa” before a b: “aab” — (ab+b)* gives strings where every a is followed by b, and the trailing a* can only add a’s at the end; “aab” would need “aa” before the last b ⇒ not generated. Answer: (i), (ii), (iii).
GATE Traps
- (a + b)* ≠ a* + b* ≠ a*b*.
- ∅* = ε, not ∅. And r∅ = ∅ (a single ∅ factor kills a concatenation).
- Always test ε: many wrong options differ from the right one only on ε (e.g. (a+b)⁺ vs (a+b)*).
- Two regexes agreeing on ten strings proves nothing; one disagreement proves they differ.
Memory Hook
Equality hunting: “smallest strings first” — compare ε, then length 1, then length 2. Most traps fall in the first three rows.
Connect the Dots
Regexes and DFAs describe the same languages — but so far that is a claim. Next chapter proves it: converting a regex into an ε-NFA (Thompson), and an automaton back into a regex (state elimination, Arden).
Self-Test
- MSQ
Which are equivalent to a*?
- (a*)*
- ε + aa*
- a*a*
- a⁺
- MSQ
Which strings distinguish (ab)* from a*b* (belong to exactly one of them)?
- ε
- ab
- aab
- abab
- MCQ
Regex for binary strings with at most one 0:
- 1*01*
- 1*(0 + ε)1*
- (1 + 0)*
- 1*0*1*
- NAT
How many strings of length 4 are in L((b + ab)*(ε + a))?
Write your answer before opening the key.
- MCQ
(rs)*r equals:
- r(sr)*
- r*s*r
- (sr)*r
- rs*r
Rule Card
- ∅ + r = r; ∅r = ∅; εr = r; ∅* = ε* = ε; (r*)* = r*; r*r* = r*; ε + rr* = r*; (rs)*r = r(sr)*.
- (r+s)* = (r*s*)* = (r*+s*)* = r*(sr*)* = (r*s)*r*.
- ≠: (r+s)* vs r*+s* vs r*s*; (rs)* vs r*s*.
- No “aa”: (b+ab)*(ε+a). At most one a: b*(ε+a)b*. Even #0: 1*(01*01*)*.
- Equality: compare shortest strings; counterexample kills; identities or minimal DFAs prove.
Concept Ledger
- regex identities
- shifting identity (rs)*r = r(sr)*
- equivalent regexes
- counterexample string
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- a(b*).
- 3 (last not a, last a, dead).
- Yes, up to renaming.
Self-test answers
- ABC — Standard identities.
- D: a⁺ excludes ε.
- CD — aab ∈ a*b* only; abab ∈ (ab)* only.
- A: In both.
- B: In both.
- B — Zero or one 0 surrounded by 1s.
- A: Exactly one 0.
- C: All strings.
- D: Allows 00.
- 8 — Strings of length 4 with no two consecutive a’s: Fibonacci count 1,2,3,5,8 → 8.
- A — Shifting identity.
- B: Allows rrr.
- C: Starts with s.
- D: Allows ss.
Flashcards
- Is (a+b)* = a* + b*?
Reveal answer
No — ab is only in the left side. - (a+b)* equals which other forms?
Reveal answer
(a*b*)*, (a*+b*)*, a*(ba*)*, (a*b)*a* - Regex: no two consecutive a’s over {a,b}?
Reveal answer
(b + ab)*(ε + a) - ε + rr* = ?
Reveal answer
r* - (rs)*r = ?
Reveal answer
r(sr)*
Exam shortcuts
- Count strings of length n with no two consecutive a’s: Fibonacci — 1, 2, 3, 5, 8, 13 for n = 0..5.
- Fast regex-equality check: write the strings of length 0, 1, 2 for each option. The odd one out shows itself.