0% found this document useful (0 votes)
126 views13 pages

15 Combinatorics Pigeonhole Principle

The document discusses the pigeonhole principle and provides examples of its applications. It introduces the principle that if you have more pigeons than holes, then some hole must contain more than one pigeon. It then gives examples of how to use the principle to prove various mathematical statements. These include problems about integers, subsets, sequences, divisibility, and birthdays. The document also discusses how the pigeonhole principle can help in competitive programming problems and provides an example of using it to find a value of a large exponential expression modulo a number.

Uploaded by

Angkur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views13 pages

15 Combinatorics Pigeonhole Principle

The document discusses the pigeonhole principle and provides examples of its applications. It introduces the principle that if you have more pigeons than holes, then some hole must contain more than one pigeon. It then gives examples of how to use the principle to prove various mathematical statements. These include problems about integers, subsets, sequences, divisibility, and birthdays. The document also discusses how the pigeonhole principle can help in competitive programming problems and provides an example of using it to find a value of a large exponential expression modulo a number.

Uploaded by

Angkur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

P T H I N K F A ST S

Competitive Programming
From Problem 2 Solution in O(1)

Combinatorics
Pigeonhole Principle

Mostafa Saad Ibrahim


PhD Student @ Simon Fraser University
Pigeonhole Principle

◼ Assume we have N=5 boxes and M=6 apples


◼ Distribute apples in boxes in whatever way
◼ There must be 1 box with at least 2 apples
◼ If you want to avoid duplicate:
◼ Put 1 apple per box. Remaining is 1 apple.
◼ To put it, one box will have 2 apples
◼ What if we have 13 apples?
◼ 1 box will have at least ⌈13/5⌉ = 3 apples
◼ Generally: ⌈N/M⌉ per a box.
Many proofs based on it
◼ The set S has 10 integers, each between 0 and 100. Prove that there are
two disjoint subsets of S that have the same sum.
◼ Given a set of N integers, there is a consecutive subset of them whose sum
is divisible by N.
◼ Every sequence of n2 + 1 distinct real numbers contains a subsequence of
length n + 1 that is either strictly increasing or strictly decreasing.
◼ Show that among any n + 1 positive integers not exceeding 2n there must
be an integer that divides one of the other integers.
◼ How many cards must be selected from a standard deck of 52 cards to
guarantee that at least three cards of the same suit are chosen?
◼ Among any group of 367 people, there must be at least two with the same
birthday
◼ Show that for every integer n there is a multiple of n that has only 0s and
1s in its decimal expansion.
Pigeonhole Principle: Example

◼ Prove: Among any N positive integers, there


exists 2 whose difference is divisible by N-1.
◼ Recall: |A-B| % X = 0 IFF A%X = B%X
◼ So, let’s compute % N-1?
◼ Then we have N-1 values, each in range [0-N-2]
◼ But, we have N numbers, then at least one mode will be
duplicate
◼ Given that 2 numbers at least has same % N-1
◼ Then, their difference must be divisible by N-1
◼ Always relate % with Pigeonhole
Pigeonhole Principle: Example

◼ Case for previous problem:


◼ Let A represents array of numbers
◼ N = 5 and A = {2, 3, 5, 7, 8}
◼ Compute A % 4 = {2, 3, 1, 3, 0}
◼ 5 numbers, with values [0-3].
◼ Pick 2 with same mode - 3 is repeated mode
◼ Then, (3, 7) are the answer
Pigeonhole Principle: Example

◼ Prove: For any N positive integers, the sum of


subset of them is divisible N
◼ Compute Accum array % N
◼ Accum[i] = {A[0] + A[1]...A[i]} % N
◼ If any Accum[i] = 0, we are done
◼ Otherwise, we have N values in range [1-N-1]
◼ Then 2 positions will have same mode
◼ Then getting numbers between then is answer
Pigeonhole Principle: Example

◼ Let A represents array of numbers


◼ N = 5 and A = {2, 4, 8 , 2 , 7}
◼ Accumulate: B = {2, 6, 14, 16, 23}
◼ Mode 5: C = {2, 1, 4, 1 , 3}
◼ Any zeros? No..remaining 4 values spread on
5 values...one of them must be repeated
◼ if yes then A[0]+A[1]...A[i] where C[i] % N = 0
◼ 2nd and 4th have mode 1
◼ Then range from 3rd till 4th is answer: 8, 2
Pigeonhole and Competitions

◼ Most of time it helps in proving, rather than a


technique to apply
◼ Read many problem examples (web/books) + proofs
◼ In some problems, it can be the major trick
◼ Sometimes comes with Modular Arithmetic
◼ Some facts in graph:
◼ A Path of M nodes (M > N) must have a node used more than once
◼ A cycle of Length M (M > N nodes), must be composed of cycles
each of Length <= N
◼ Every graph contains two vertices of same degree
Let’s try a competitive example..direct case
Powers tower % M

◼ Let’s compute: 2^3^4^5^6^7^8 % 56


◼ We can solve it using Euler theorem
◼ let’s simplify it, compute 2X % 56
◼ where x is very large, e.g. x = 3^4^5^6^7^8
◼ Imagine we compute 2i%M for i [0 - OO]
◼ We know we have M mod values: [0 - M-1]
◼ Pigeonhole: values repeat in maximum M + 1 iterations
◼ Then computing X should have same value as one of the
first powers in range [0-M-1]
◼ But which 2i%M correspond to 2x%M ?
◼ Let’s simulate it
Powers tower % M

i 0 1 2 3 4 5 6 7

2i % 56 1 2 4 8 16 32 8 16

◼ 2^6 is same as 2^3. Then 2^7 must = 2^4...etc


◼ {8,16,32} is cycle and {1,2,4} is precycle
◼ Let length of the cycle be L, and length of precycle be P
◼ Given some X, we can compute its i position
◼ i = P + ( L + X % L - P % L ) % L [if X > P]
◼ Then?
◼ Solve subproblem X % L in same manner
◼ Then compute 2i % M
‫ﺗﻢ ﺑﺤﻤﺪ ﷲ‬

‫ﻋﻠﻤﻜﻢ ﷲ ﻣﺎ ﯾﻨﻔﻌﻜﻢ‬

‫وﻧﻔﻌﻜﻢ ﺑﻤﺎ ﺗﻌﻠﻤﺘﻢ‬

‫وزادﻛﻢ ﻋﻠﻤﺎ ً‬
Problems

◼ UVA (11237), SRM283-1-2(FactorialTower),


Hackerrank(A Perfect Set - GoDaddy
Hackathon),

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy