CS Atlas GATE 2027
TOC course
0 / 91 complete

TOC/Phase 0 · Foundations

Lesson 0.2.4 · Item 5 of 91

Pigeonhole principle

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

On this page

Recall warm-up

  1. Give the contrapositive of “If L is handled by finite memory then L has property X.”
    Stuck? Peek at 0.2.3 Proof techniques
    • P ⇒ Q false only when P true, Q false. Contrapositive ¬Q ⇒ ¬P ≡ original. Converse/inverse are NOT.
    • Contradiction: assume ¬S, derive the impossible. Used for “no machine can…” proofs.
    • Induction: base S(n₀) + step S(k) ⇒ S(k+1). Strong induction assumes all S(≤k).
    • One counterexample kills a “for all”. Examples never prove it.

    Read lesson 0.2.3

  2. How many functions from a 2-element set to a 3-element set?
    Stuck? Peek at 0.2.2 Functions, relations and equivalence classes
    • Relation ⊆ A × B. Function: every input exactly one output. Partial function: some inputs have none.
    • #functions A→B = |B|^|A|. #one-to-one (|A| ≤ |B|) = |B|·(|B|−1)···. #relations on n-set = 2^(n²).
    • Equivalence = reflexive + symmetric + transitive. Classes partition the set; number of classes = index.
    • Finer relation (refinement) ⇒ more classes; every fine class sits inside a coarse class.

    Read lesson 0.2.2

  3. Is “same last letter” on non-empty words an equivalence relation?
    Stuck? Peek at 0.2.2 Functions, relations and equivalence classes
    • Relation ⊆ A × B. Function: every input exactly one output. Partial function: some inputs have none.
    • #functions A→B = |B|^|A|. #one-to-one (|A| ≤ |B|) = |B|·(|B|−1)···. #relations on n-set = 2^(n²).
    • Equivalence = reflexive + symmetric + transitive. Classes partition the set; number of classes = index.
    • Finer relation (refinement) ⇒ more classes; every fine class sits inside a coarse class.

    Read lesson 0.2.2

The Hook

Your machine has 5 modes. It reads an input of 6 symbols. Before reading and after each symbol, it is in some mode — that’s 7 moments, but only 5 possible modes. Without knowing anything else about the machine, you can be certain it was in the same mode at two different moments. That certainty is the pigeonhole principle, and it is the engine behind proving that finite-memory machines cannot count forever.

Predict First

How many people must be in a room to guarantee that two share a birth month?

Core Concept

Prediction check

Answer: 13. With 12 people, each could have a different month. With 13, the 12 months are “boxes” and 13 people can’t all be in different boxes.

12 people can all differ. The 13th has nowhere new to go.
12 people can all differ. The 13th has nowhere new to go.

The principle

Pigeonhole principle: if n + 1 (or more) objects are placed into n boxes, at least one box holds at least 2 objects.

It tells you a collision exists, not where. That’s exactly how it is used: “some mode repeats” — we don’t know which, and we don’t need to.

n + 1 objects, n boxes: a collision is forced — but the principle never says which box.
n + 1 objects, n boxes: a collision is forced — but the principle never says which box.

Generalized pigeonhole

If N objects go into k boxes, some box holds at least ⌈N/k⌉ objects (⌈x⌉ = round up). 100 students in 7 sections ⇒ some section has ≥ ⌈100/7⌉ = 15. To guarantee m objects in some box you need (m−1)·k + 1 objects.

15S115S214S314S414S514S614S7
students per section (most even spread of 100)
Even the fairest spread of 100 into 7 leaves some section with ⌈100/7⌉ = 15.

The machine version

A machine with n modes reads an input of length m ≥ n. It passes through m + 1 moments (start, after symbol 1, …, after symbol m). Since m + 1 > n, some mode appears twice. Between those two moments the machine read a stretch of input that took it from a mode back to the same mode — a loop. Repeat that stretch and the machine can’t tell the difference: it returns to the same mode again. This is the seed of the “pumping” idea in Phase 2.

steps illustration
A 3-mode machine reading 4 symbols: modes at each moment.

How to use it in a proof

  1. Identify the objects (moments, numbers, people).
  2. Identify the boxes (modes, remainders, months).
  3. Show objects > boxes.
  4. Conclude two objects share a box, and exploit that.
Objects
moments, numbers, people
Boxes
modes, remainders, months
Objects > boxes?
count both
Collision
two share a box — use it
The four-step recipe for every pigeonhole proof.

Putting it together

  • n + 1 objects in n boxes force a shared box; N objects in k boxes put at least ⌈N/k⌉ in one.
  • An n-mode machine reading at least n symbols must repeat a mode.
  • A repeated mode means the input between the repeats is a loop that can be repeated — the seed of the pumping lemma.

Visual

Machine with 3 modes {A,B,C} reading "x y z w" (4 symbols → 5 moments)

 moment:   0     1     2     3     4
 mode:     A ─x→ B ─y→ C ─z→ B ─w→ A
                 ▲           ▲
                 └── same mode B at moments 1 and 3
 the stretch "y z" took B back to B  →  a loop:
 reading "x (y z)(y z)(y z) w" passes B, B, B, B ... and ends exactly as before.

Worked Examples

Easy

A drawer has 10 black and 10 white socks. In the dark, how many must you pull to guarantee a matching pair?

Show the full solution

Boxes = 2 colours. 3 socks ⇒ two share a colour. Answer 3.

Medium

Show that among any 5 integers, two have the same remainder when divided by 4.

Show the full solution

Boxes = remainders {0,1,2,3} (4 boxes), objects = 5 integers. 5 > 4 ⇒ two share a remainder, so their difference is divisible by 4. ∎

GATE-level

A machine with 7 modes reads an input of length 7. Is a repeated mode guaranteed? What about input length 6?

Show the full solution

Length 7 ⇒ 8 moments > 7 modes ⇒ guaranteed. Length 6 ⇒ 7 moments = 7 modes ⇒ not guaranteed (each moment could use a different mode). So the threshold is “input length ≥ number of modes”. Remember this exact threshold; it becomes the “pumping length”.

GATE Traps

  • Count moments, not symbols: m symbols give m + 1 moments (including the start).
  • Pigeonhole proves existence of a collision; it never tells you which box.
  • “Guarantee” questions ask for the worst case: one more than the maximum without collision.

Memory Hook

Thirteen people, twelve months: someone has to share. More pigeons than holes ⇒ a crowded hole.

Connect the Dots

We’ve been drawing machines as dots (modes) with arrows (moves). That picture is a directed graph. Next: the vocabulary of graphs — paths, cycles, and which nodes you can reach — which is exactly how we’ll read machine diagrams.

Self-Test

  1. NAT

    Minimum number of integers needed to guarantee two have the same remainder mod 10?

    Write your answer before opening the key.

  2. NAT

    50 letters are sorted into 8 mailboxes. At least how many letters must some mailbox hold?

    Write your answer before opening the key.

  3. MCQ

    A machine with n modes reads an input of length m. A repeated mode is guaranteed whenever:

    1. m ≥ n − 1
    2. m ≥ n
    3. m ≥ n + 1
    4. m ≥ 2n
  4. MSQ

    Which conclusions does pigeonhole justify?

    1. Among 367 people two share a birthday (ignoring leap issues beyond 366 days)
    2. Among 3 integers two have the same parity (even/odd)
    3. Among 10 people two were born on the same weekday
    4. Among 7 people two were born on the same weekday

Rule Card

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

Concept Ledger

  • pigeonhole principle
  • generalized pigeonhole ⌈N/k⌉
  • moments of a run (m symbols ⇒ m+1 moments)
  • repeated mode ⇒ loop

Answer Vault

Reveal answers when you’re ready

Warm-up answers

  1. “If L does not have property X, then L is not handled by finite memory.”
  2. 3² = 9.
  3. Yes — reflexive, symmetric, transitive.

Self-test answers

  1. 11 — 10 remainder boxes; 11 objects force a collision.
  2. 7 — ⌈50/8⌉ = ⌈6.25⌉ = 7.
  3. B — m symbols ⇒ m + 1 moments; need m + 1 > n, i.e. m ≥ n.
    • A: m = n−1 gives n moments, which can all differ.
    • C: True but not the weakest condition; m = n already suffices.
    • D: Far more than needed.
  4. ABC — Each case has more objects than boxes.
    • D: 7 people, 7 weekdays: no guarantee.

Flashcards

  1. Pigeonhole principle?
    Reveal answern+1 objects in n boxes ⇒ some box has at least 2.
  2. Generalized pigeonhole: N objects, k boxes?
    Reveal answerSome box has at least ⌈N/k⌉.
  3. When must an n-mode machine repeat a mode on an input of length m?
    Reveal answerWhen m ≥ n (m+1 moments > n modes).

Ready for the next idea?

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