CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 0 · Foundations

Lesson 0.3.3 · Item 10 of 91

Operations on languages

Read at your own pace. Try the questions before opening the answers.

On this page

Recall warm-up

  1. |∅| and |{ε}|?
    Stuck? Peek at 0.3.2 Σᵏ, Σ*, Σ⁺ and languages
    • |Σᵏ| = |Σ|ᵏ; Σ⁰ = {ε}; Σ* = ⋃ Σᵏ (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.

    Read lesson 0.3.2

  2. How many binary strings of length 4 have exactly one 1?
    Stuck? Peek at 0.3.2 Σᵏ, Σ*, Σ⁺ and languages
    • |Σᵏ| = |Σ|ᵏ; Σ⁰ = {ε}; Σ* = ⋃ Σᵏ (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.

    Read lesson 0.3.2

  3. If A − B is written with ∩ and complement, what is it?
    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(∅) = {∅}.

    Read lesson 0.2.1

The Hook

A website accepts a username followed by a digit. The set of valid usernames is one language, the set of digits another; the valid logins are “a username glued to a digit”. A log file is “any number of valid lines in a row”. Gluing and repeating are new operations that sets of numbers don’t have, but sets of strings do. They are exactly the operations regular expressions are made of.

Predict First

Let L = {a, ab}. How many strings are in L·L = { xy : x ∈ L, y ∈ L }? (Careful — guess, then check for duplicates.)

Core Concept

Prediction check

Pairs: a·a = aa, a·ab = aab, ab·a = aba, ab·ab = abab. All different: 4. But with L = {a, aa}: a·aa = aaa and aa·a = aaa collide, so L·L = {aa, aaa, aaaa} has only 3. |L₁L₂| ≤ |L₁|·|L₂|, with equality only when no collisions occur.

x \ yaab
aaaaab
ababaabab
L·L for L = {a, ab}: every row glued to every column — 4 distinct strings. With L = {a, aa}, a·aa and aa·a collide, so only 3.

Set operations still work

Languages are sets, so: L₁ ∪ L₂, L₁ ∩ L₂, L₁ − L₂, and the complement L̅ = Σ* − L (the universe is Σ*). Complement of “strings starting with a” over {a,b} is “strings not starting with a” = strings starting with b, plus ε. Never forget ε in complements.

L₁ = starts with a, L₂ = ends with b, universe Σ*. The complement of L₁ contains ε.
L₁ = starts with a, L₂ = ends with b, universe Σ*. The complement of L₁ contains ε.

Concatenation of languages

L₁L₂ = { xy | x ∈ L₁, y ∈ L₂ }.
  • L{ε} = {ε}L = L ({ε} is the identity).
  • L∅ = ∅L = ∅ (nothing to pair with — ∅ is the “zero”).
  • Not commutative: {a}{b} = {ab} but {b}{a} = {ba}.
·ε00
00000
11100
{0,1}·{ε,00} = {0, 1, 000, 100}. Swap the order and you get 001 instead of 100.

Powers of a language

L⁰ = {ε}, L¹ = L, Lⁿ⁺¹ = LⁿL. Lⁿ = all strings made by gluing n strings from L. {a,b}ⁿ = Σⁿ. Note ∅⁰ = {ε} (by definition) but ∅ⁿ = ∅ for n ≥ 1.

L⁰
{ε}
· L
L¹
{a, ab}
· L
L²
{aa, aab, aba, abab}
· L
L³
8 strings…
Powers: glue n copies.

Kleene star and plus

L* = L⁰ ∪ L¹ ∪ L² ∪ … — glue any number (zero or more) of strings from L.
L⁺ = L¹ ∪ L² ∪ … — one or more.
  • ε ∈ L* always. ε ∈ L⁺ iff ε ∈ L.
  • L⁺ = LL* = L*L. L* = L⁺ ∪ {ε}.
  • ∅* = {ε}; {ε}* = {ε}; ∅⁺ = ∅.
  • (L*)* = L*; L*L* = L*.
  • If L contains at least one non-empty string, L* is infinite.

Example: {ab}* = {ε, ab, abab, ababab, …}. {a, b}* = Σ*. {aa}* = all strings of a’s with even length.

L* zero or more pieces — always contains ε
L⁺ one or more pieces
L exactly one piece
Star and plus. Special cases: ∅* = {ε}, {ε}* = {ε}, ∅⁺ = ∅.

Reversal of a language

Lᴿ = { wᴿ | w ∈ L }. {ab, abc}ᴿ = {ba, cba}. (L₁L₂)ᴿ = L₂ᴿL₁ᴿ.

w ∈ Lwᴿ ∈ Lᴿ
abba
abccba
Reversal of a language reverses each string.

Counting strings of a given length in a language

  • Positions argument: binary strings of length n with exactly r 1’s: C(n, r).
  • Fixed parts: length-n binary strings starting with 01: 2ⁿ⁻² (the other n−2 positions are free).
  • Inclusion–exclusion: start with a OR end with b (length n ≥ 2, over {a,b}): 2ⁿ⁻¹ + 2ⁿ⁻¹ − 2ⁿ⁻² .
  • Complement counting: “contains at least one a” = all − “no a’s” = 2ⁿ − 1.
start with a
a _ _ _ _ _ → 2⁵ = 32
end with bb
_ _ _ _ b b → 2⁴ = 16
both
a _ _ _ b b → 2³ = 8
either
32 + 16 − 8 = 40
Counting length-6 strings by fixing positions and using inclusion–exclusion.

Putting it together

  • Concatenation glues; L{ε} = L, L∅ = ∅; it is not commutative.
  • Star = zero or more (always ε), plus = one or more; ∅* = {ε}* = {ε}.
  • Count strings by fixing positions, choosing positions C(n,r), inclusion–exclusion, or complement.

Visual

L = {a, ab}
L⁰ = {ε}
L¹ = {a, ab}
L² = {aa, aab, aba, abab}
L* = {ε, a, ab, aa, aab, aba, abab, aaa, ...}

identity & zero table
 ┌──────────────┬───────────────┐
 │ L{ε} = L     │ L∅ = ∅        │
 │ ∅* = {ε}     │ {ε}* = {ε}    │
 │ ∅⁺ = ∅       │ ∅⁰ = {ε}      │
 │ L⁺ = LL*     │ L* = L⁺ ∪ {ε} │
 └──────────────┴───────────────┘

Worked Examples

Easy

L₁ = {0, 1}, L₂ = {ε, 00}. List L₁L₂ and L₂L₁.

Show the full solution

L₁L₂ = {0, 1, 000, 100}. L₂L₁ = {0, 1, 000, 001}. Different (100 vs 001): concatenation is not commutative.

Medium

Over {a,b}, how many strings of length 6 start with a or end with bb?

Show the full solution

Start with a: 2⁵ = 32. End with bb: 2⁴ = 16. Both: a _ _ _ b b → 2³ = 8. Total = 32 + 16 − 8 = 40.

GATE-level

Let L = {a, aa}. Which strings are in L* and how many strings of length 5 does L* contain? Also: is ∅* ∪ {ε}* equal to ∅?

Show the full solution

Any aᵏ with k ≥ 0 is a sum of 1s and 2s, so L* = {a}* — all strings of a’s. Length 5: just 1 string (aaaaa). (The number of ways to build it — 8 — is a different question; a language counts strings, not ways.) ∅* ∪ {ε}* = {ε} ∪ {ε} = {ε} ≠ ∅.

GATE Traps

  • ∅* = {ε}, not ∅. The star always contains ε.
  • L∅ = ∅ (not L). L{ε} = L.
  • Complement is relative to Σ* — include ε and every length.
  • A language counts strings, not the number of ways to build them.
  • |L₁L₂| can be less than |L₁|·|L₂| when concatenations collide.

Memory Hook

Star = “zero or more” = a vending machine for strings that is always allowed to give you nothing (ε).

Connect the Dots

We have the full vocabulary: strings, languages, and operations on languages. One last idea completes Phase 0: every yes/no question is a language, so “solving a problem” means “telling which strings are in a set”.

Self-Test

  1. MCQ

    Which equals ∅*?

    1. ∅
    2. {ε}
    3. Σ*
    4. undefined
  2. NAT

    Over {0,1}, how many strings of length 8 contain at least one 0?

    Write your answer before opening the key.

  3. MSQ

    Which are always true for any language L?

    1. L{ε} = L
    2. L∅ = L
    3. ε ∈ L*
    4. L⁺ = L* − {ε}
  4. NAT

    L = {ab, ba}. How many strings are in L³?

    Write your answer before opening the key.

  5. MCQ

    Over {a,b}, the complement of L = {w : w starts with a} is:

    1. {w : w starts with b}
    2. {w : w starts with b} ∪ {ε}
    3. {w : w ends with b}
    4. Σ⁺

Rule Card

  • 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.

Concept Ledger

  • language union/intersection/complement (w.r.t. Σ*)
  • concatenation L₁L₂
  • language power Lⁿ, L⁰ = {ε}
  • Kleene star L*
  • Kleene plus L⁺
  • reversal of a language Lᴿ
  • counting strings of a given length

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. 0 and 1.
  2. C(4,1) = 4.
  3. A ∩ B̅.

Self-test answers

  1. B — Star includes zero repetitions: ε.
    • A: The star always contains ε.
    • C: Nothing to repeat.
    • D: It is defined.
  2. 255 — 2⁸ − 1 (remove 11111111).
  3. AC — ε is the identity; star always contains ε.
    • B: L∅ = ∅.
    • D: If ε ∈ L then ε ∈ L⁺, so L⁺ = L* (not L* − {ε}).
  4. 8 — Every length-6 concatenation of three blocks is distinct because blocks are fixed-length 2 and different: 2³ = 8.
  5. B — ε does not start with a, so it is in the complement.
    • A: Misses ε.
    • C: Unrelated.
    • D: Contains strings starting with a.

Flashcards

  1. ∅* = ? and {ε}* = ?
    Reveal answerBoth equal {ε}.
  2. L∅ = ?
    Reveal answer∅
  3. Relation between L⁺ and L*?
    Reveal answerL⁺ = LL*; L* = L⁺ ∪ {ε}.
  4. Strings of length n over {a,b} starting with a OR ending with b?
    Reveal answer2ⁿ⁻¹ + 2ⁿ⁻¹ − 2ⁿ⁻² (inclusion–exclusion).

Exam shortcuts

  • “At least one X” counts: total minus “no X”. Binary length n with at least one 1: 2ⁿ − 1.
  • Star of a set of one-symbol strings: {a, aa}* = {a}* because every length is reachable with 1s.

Ready for the next idea?

Mark this item complete when you’ve finished reading and working through it.