CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 0 · Foundations

Lesson 0.3.4 · Item 11 of 91

Problems as languages

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

On this page

Recall warm-up

  1. Is ε in L⁺ when ε ∉ 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.

    Read lesson 0.3.3

  2. Over {a,b}, how many strings of length ≤ 3?
    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. What does the pigeonhole principle guarantee for an n-mode machine reading n symbols?
    Stuck? Peek at 0.2.4 Pigeonhole principle
    • n + 1 objects in n boxes ⇒ some box has ≥ 2.
    • N objects in k boxes ⇒ some box has ≥ ⌈N/k⌉. To force m in a box: (m−1)k + 1 objects.
    • Machine with n modes, input length ≥ n ⇒ some mode repeats ⇒ a loop in the input.

    Read lesson 0.2.4

The Hook

“Is 91 a prime number?” sounds like a question about numbers, not strings. But a computer only ever sees strings — 91 arrives as the characters 1011011 in binary. So the question becomes: is the string 1011011 in the set of strings that encode primes? Every yes/no problem turns into a membership question about a language. This is the bridge that makes TOC work.

Predict First

The problem “is this binary number even?” is the same as membership in which language over {0,1}? Describe it by a simple property of the string.

Core Concept

Prediction check

A binary number is even exactly when its last bit is 0. So the language is {w ∈ {0,1}⁺ | w ends with 0}. A deep-sounding arithmetic question became a one-glance property of the string.

1010last bit 0 ⇒ even
1010 = 10. Evenness of the number is just “ends with 0” for the string.

Encoding

To feed any object to a machine, write it as a string: a number in binary, a list as symbols separated by commas, a graph as a list of edges, even a whole program as its source text. We write ⟨X⟩ for “the string that encodes X”.

Object
number 13, a graph, a program
Encoding ⟨X⟩
1101 · edge list · source text
String
what a machine reads
Anything can be written as a string.

Problem = language

A decision problem P corresponds to the language L_P = { ⟨x⟩ | the answer for x is yes }. Solving P = building a machine that accepts exactly the strings in L_P and rejects all others.

This is called the membership problem: given a string w, is w ∈ L? “The machine accepts L” means: it says yes on every w ∈ L and does not say yes on any w ∉ L.

Problem P
is n even?
becomes
Language L_P
binary strings ending in 0
solved by
Machine M
says yes ⇔ w ∈ L_P
Solving a problem = deciding membership in its language.

Examples

  • PALINDROME = { w ∈ {a,b}* | w = wᴿ }.
  • BALANCED = strings of ( and ) where brackets match properly.
  • EQUAL = { w ∈ {a,b}* | |w|ₐ = |w|_b }.
  • DIV3 = binary strings whose value is divisible by 3.

From Lesson 0.1.1 you already know which of these feel “finite-memory”: DIV3 only needs the remainder (3 possibilities). BALANCED and EQUAL need an unbounded count. PALINDROME needs to remember the whole first half. Phases 1–3 make these intuitions precise.

Languagefact to carry while readingfinite memory?
DIV3remainder 0, 1 or 2yes
BALANCEDopens − closes (unbounded)no
EQUAL#a − #b (unbounded)no
PALINDROMEthe whole first halfno
The memory test from Lesson 0.1.1, applied to languages.

The roadmap from here

Each phase introduces a machine with more memory and asks: which languages can it accept?

  1. Finite-memory machines (Phase 1–2).
  2. Machines with a pile of plates (Phase 3).
  3. Machines with an endless notebook (Phase 4).
  4. Languages no machine can handle (Phase 5).
All languages
handled with an endless notebook Phase 4
handled with a pile of plates Phase 3
handled with finite memory Phases 1–2
The nesting you will build, phase by phase.

Putting it together

  • Any object can be encoded as a string ⟨X⟩.
  • A yes/no problem is the language of its yes-instances; solving it = answering membership.
  • Which machine can solve it depends on the memory needed — the rest of the course.

Visual

   problem                       language (set of yes-strings)
 ┌──────────────────────┐        ┌──────────────────────────────────┐
 │ is n even?           │  ───►  │ { w ∈ {0,1}⁺ : w ends in 0 }     │
 │ is it a palindrome?  │  ───►  │ { w : w = wᴿ }                   │
 │ brackets balanced?   │  ───►  │ { (), (()), ()(), ... , ε }      │
 └──────────────────────┘        └──────────────────────────────────┘
      solve problem  ≡  build a machine M with  "M says yes on w"  ⇔  w ∈ L

Worked Examples

Easy

Write the problem “does the input contain the letter c?” over Σ = {a,b,c} as a language.

Show the full solution

L = { w ∈ Σ* | |w|_c ≥ 1 } = Σ*cΣ* — strings of the form (anything) c (anything).

Medium

Is the string 1001 in DIV3? Is 110?

Show the full solution

1001₂ = 9 → divisible by 3 → yes. 110₂ = 6 → yes. 111₂ = 7 would be no.

GATE-level

L = { w ∈ {a,b}* : |w|ₐ = 2|w|_b }. Which of ε, aab, aba, ab, aaabb are in L?

Show the full solution

ε: 0 = 0 ✓. aab: 2 = 2·1 ✓. aba: 2 = 2·1 ✓. ab: 1 ≠ 2 ✗. aaabb: 3 ≠ 4 ✗. So ε, aab, aba. Note ε satisfies every “count equals count” condition — check it every time.

GATE Traps

  • ε is in many “count” languages (0 = 0). Always test ε.
  • “The machine accepts L” requires both directions: yes on all of L and no yes outside L.
  • Encodings matter only up to “reasonable”: binary vs decimal does not change which problems are solvable.

Memory Hook

Every question is a guest list: the language is the list, and the machine is the bouncer checking names at the door.

Connect the Dots

Phase 0 is complete. You know the objects (strings, languages) and the tools (sets, functions, equivalence classes, proofs, pigeonhole, graphs). Phase 1 builds the first real machine: one with a fixed, finite set of modes — and gives those modes their proper name.

Self-Test

  1. MCQ

    The problem “is the binary number divisible by 2?” corresponds to which language over {0,1}?

    1. strings starting with 0
    2. strings ending with 0
    3. strings with even length
    4. strings with an even number of 1s
  2. MSQ

    L = { w ∈ {a,b}* : |w|ₐ = |w|_b }. Which strings are in L?

    1. ε
    2. abba
    3. aab
    4. baab
  3. NAT

    How many strings of length 4 over {a,b} are in L = { w : |w|ₐ = |w|_b }?

    Write your answer before opening the key.

  4. MCQ

    “Machine M accepts language L” means:

    1. M says yes to some strings of L
    2. M says yes to exactly the strings of L
    3. M says no to all strings outside L only
    4. M runs forever on strings of L

Rule Card

  • Problem P ↔ language L_P = {⟨x⟩ : answer yes}. ⟨X⟩ = string encoding of X.
  • Solving P = machine M with: M says yes on w ⇔ w ∈ L_P (membership).
  • Always test ε against count conditions.

Concept Ledger

  • encoding ⟨X⟩
  • problem as a language L_P
  • membership problem (is w ∈ L?)
  • machine accepts a language (exactly the strings of L)

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. No.
  2. 15.
  3. Some mode repeats (n+1 moments, n modes).

Self-test answers

  1. B — Parity is decided by the last bit.
    • A: Leading digit is irrelevant.
    • C: Length is unrelated to value parity.
    • D: 11₂ = 3 has two 1s but is odd.
  2. ABD — Equal counts; ε has 0 and 0.
    • C: 2 a’s, 1 b.
  3. 6 — Choose 2 positions for a: C(4,2) = 6.
  4. B — Yes on all of L and on nothing else.
    • A: Must be all of L.
    • C: Only half the requirement.
    • D: That gives no verdict.

Flashcards

  1. What does “M accepts L” mean?
    Reveal answerM says yes on every string in L and on no string outside L.
  2. Binary numbers divisible by 2 as a language?
    Reveal answerStrings ending in 0.
  3. Membership problem?
    Reveal answerGiven w, decide whether w ∈ L.

Ready for the next idea?

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