Recall warm-up
- How many suffixes does a string of length 5 have?
Stuck? Peek at 0.3.1 Alphabets and strings
- Σ finite non-empty; string = finite sequence; |ε| = 0; εw = wε = w.
- |xy| = |x| + |y|; wⁿ repeats w; w⁰ = ε; (xy)ᴿ = yᴿxᴿ.
- Length n: n+1 prefixes, n+1 suffixes; ≤ n(n+1)/2 + 1 distinct substrings (equality iff all pieces distinct, e.g. all symbols distinct).
- Substring = contiguous; subsequence = may skip.
- What is (abc)ᴿ?
Stuck? Peek at 0.3.1 Alphabets and strings
- Σ finite non-empty; string = finite sequence; |ε| = 0; εw = wε = w.
- |xy| = |x| + |y|; wⁿ repeats w; w⁰ = ε; (xy)ᴿ = yᴿxᴿ.
- Length n: n+1 prefixes, n+1 suffixes; ≤ n(n+1)/2 + 1 distinct substrings (equality iff all pieces distinct, e.g. all symbols distinct).
- Substring = contiguous; subsequence = may skip.
- Is ∅ ⊆ every set?
Stuck? Peek at 0.2.1 Sets
- x ∈ A (element) vs X ⊆ A (subset). ∅ ⊆ every set. A = B ⇔ A ⊆ B and B ⊆ A.
- A ∪ B, A ∩ B, A − B = A ∩ B̅, A̅ = U − A. De Morgan: (A∪B)̅ = A̅∩B̅, (A∩B)̅ = A̅∪B̅.
- |A ∪ B| = |A| + |B| − |A ∩ B|. |A × B| = |A|·|B|. |P(A)| = 2^|A|.
- |∅| = 0, |{∅}| = 1, P(∅) = {∅}.
The Hook
A machine says yes to some inputs and no to others. The collection of all inputs it says yes to is a set of strings. That set is the single most important object in TOC: it is called a language. “What does this machine do?” becomes “what language does it accept?”.
Predict First
Over the alphabet {a, b}, how many strings have length exactly 3? And how many have length at most 3?
Core Concept
Prediction check
Length exactly 3: 2³ = 8 (each of 3 positions is a or b). At most 3: lengths 0,1,2,3 → 1 + 2 + 4 + 8 = 15 (don’t forget ε, the single string of length 0).
Σᵏ — all strings of one length
Σᵏ = the set of all strings over Σ of length exactly k. |Σᵏ| = |Σ|ᵏ. Σ⁰ = {ε} (one string, the empty one — so |Σ⁰| = 1, not 0).
Σ* and Σ⁺
Σ⁺ = Σ¹ ∪ Σ² ∪ … = all non-empty strings = Σ* − {ε}.
Σ* is infinite, but every individual string in it is finite. This is the universe we work in from now on.
Strings of length ≤ n over k symbols: 1 + k + k² + … + kⁿ = (kⁿ⁺¹ − 1)/(k − 1). For k = 2: 2ⁿ⁺¹ − 1.
Language
Examples over Σ = {a, b}:
- L₁ = {a, ab, abb} — finite (3 strings).
- L₂ = {w | w starts with a} — infinite.
- L₃ = {aⁿbⁿ | n ≥ 0} = {ε, ab, aabb, aaabbb, …} — infinite.
- Σ* itself, and Σ⁺.
∅ versus {ε}
Two tiny languages that GATE loves to confuse:
- ∅ — the empty language. It contains no strings at all. |∅| = 0. A machine that says no to everything accepts ∅.
- {ε} — contains exactly one string, the empty string. |{ε}| = 1. A machine that says yes only to the empty input accepts {ε}.
Memorize: ∅ is an empty box; {ε} is a box with one blank sheet of paper in it.
Ordering strings: shortlex
To list Σ* one by one, use shortlex (canonical) order: shorter strings first; equal lengths in dictionary order. Over {a,b}: ε, a, b, aa, ab, ba, bb, aaa, … Every string appears at a finite position. (Plain dictionary order would never get past a, aa, aaa, … — b would never appear.)
Putting it together
- |Σᵏ| = |Σ|ᵏ, Σ⁰ = {ε}; Σ* is all strings, Σ⁺ = Σ* − {ε}.
- A language is any set of strings — any subset of Σ*.
- ∅ (no strings) and {ε} (one string) are different; check ε in every counting question.
Visual
Σ = {a,b}
Σ⁰ = {ε} |Σ⁰| = 1
Σ¹ = {a, b} |Σ¹| = 2
Σ² = {aa, ab, ba, bb} |Σ²| = 4
Σ³ = {aaa,aab,aba,abb,baa,bab,bba,bbb} |Σ³| = 8
─────────────────────────────────────────────
Σ* = Σ⁰ ∪ Σ¹ ∪ Σ² ∪ ... (infinite) Σ⁺ = Σ* − {ε}
∅ = { } no strings |∅| = 0
{ε} = { ε } one empty string |{ε}| = 1
Σ* ⊇ L ⊇ ∅ every language sits between ∅ and Σ*Worked Examples
Over Σ = {0,1,2}, how many strings of length 4?
Show the full solution
|Σ|⁴ = 3⁴ = 81.
Over {a,b}, how many strings of length ≤ 4?
Show the full solution
1 + 2 + 4 + 8 + 16 = 31 = 2⁵ − 1.
Over {a,b}, how many strings of length 5 have exactly two a’s? How many languages over {a,b} contain only strings of length ≤ 2?
Show the full solution
Choose positions of the two a’s: C(5,2) = 10. Strings of length ≤ 2: 1 + 2 + 4 = 7; any subset of these 7 is such a language: 2⁷ = 128 languages (including ∅).
GATE Traps
- ∅ ≠ {ε}. |∅| = 0, |{ε}| = 1. Σ⁰ = {ε}, not ∅.
- Σ* contains ε; Σ⁺ does not. Σ⁺ = Σ* − {ε}.
- “Length at most n” includes length 0 (the string ε) — the most common off-by-one in counting questions.
- Σ* is infinite, but every string in it is finite. There is no “infinitely long string” in Σ*.
Memory Hook
ε is a blank sheet of paper; {ε} is a folder with that blank sheet in it; ∅ is an empty folder.
Connect the Dots
A language is a set, so we can union, intersect and complement languages. But strings can also be glued together, so languages get extra operations: concatenation and the star. Those are next — and they are the building blocks of regular expressions in Phase 2.
Self-Test
- NAT
Over Σ = {a, b, c}, how many strings have length at most 2?
Write your answer before opening the key.
- MCQ
Which is true?
- ∅ = {ε}
- |{ε}| = 0
- Σ⁰ = {ε}
- ε ∈ Σ⁺
- MSQ
Over Σ = {0,1}, which sets are languages over Σ?
- ∅
- {ε}
- Σ*
- {0, 01, 2}
- NAT
Over {a,b}, how many strings of length 6 contain exactly three b’s?
Write your answer before opening the key.
- MCQ
In shortlex order over {a,b}, which string comes 6th (ε is 1st)?
- ab
- ba
- aa
- bb
Rule Card
- |Σᵏ| = |Σ|ᵏ; Σ⁰ = {ε}; Σ* = ⋃ Σᵏ (k ≥ 0); Σ⁺ = Σ* − {ε}.
- #strings of length ≤ n over k symbols = (kⁿ⁺¹ − 1)/(k − 1); binary: 2ⁿ⁺¹ − 1.
- Language = any subset of Σ*. ∅ (no strings) ≠ {ε} (one string). Exactly r of one symbol in length n (binary): C(n, r).
- Shortlex order lists every string at a finite position.
Concept Ledger
- Σᵏ (strings of length k)
- Σ* (all strings)
- Σ⁺ (non-empty strings)
- language L ⊆ Σ*
- finite / infinite language
- empty language ∅ vs {ε}
- shortlex order
Answer Vault
Reveal answers when you’re ready
Warm-up answers
- 6.
- cba.
- Yes.
Self-test answers
- 13 — 1 + 3 + 9.
- C — The only string of length 0 is ε.
- A: One has no strings, one has one string.
- B: |{ε}| = 1.
- D: Σ⁺ excludes ε.
- ABC — Any subset of Σ* is a language.
- D: 2 is not a symbol of Σ, so “2” is not in Σ*.
- 20 — C(6,3) = 20.
- B — ε, a, b, aa, ab, ba.
- A: 5th.
- C: 4th.
- D: 7th.
Flashcards
- ∅ vs {ε}?
Reveal answer
∅ has no strings (size 0); {ε} has one string, the empty string (size 1). - Σ⁺ in terms of Σ*?
Reveal answer
Σ⁺ = Σ* − {ε} - Number of binary strings of length ≤ n?
Reveal answer
2ⁿ⁺¹ − 1 - What is a language?
Reveal answer
Any set of strings over Σ, i.e. any subset of Σ*.