UPI Study › Courses › Discrete Mathematics › Free lessons › Lesson 5.3 Free with a free account
The Pigeonhole Principle
Discrete Mathematics · Chapter 5: Counting Methods and Basic ProbabilitySection 5.3 · lesson 29 of 879 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Discrete Mathematics.
Lesson complete
Earn the 4 college credits for Discrete Mathematics
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Permutations and Ordered Arrangements →← The Addition and Multiplication RulesNext lesson: Permutations and Ordered Arrangements →
In this lesson
Why overlaps are guaranteed in finite collections.
- State and prove the simple pigeonhole principle
- Use the generalized form to get a numeric floor
- Solve the socks and shared-birthday problems
- Separate a certainty from a probability threshold
Transcript
Everything said in the video, section by section (1,355 words). Read along, or search it.
Counting Methods and Basic Probability
The Pigeonhole Principle
This section is about the pigeonhole principle, one of the simplest and most widely used ideas in combinatorics. We'll state it in its basic form, then extend it to a general version that gives an actual number. And we'll work through the two classic illustrations every treatment of the topic reaches eventually. Socks in a drawer, and shared birthdays.
The Opening Problem
150 Records, 100 Buckets
A hash table stores records by computing a hash of each record's key, and using the result to pick one of a fixed number of buckets. Suppose a table has one hundred buckets, and one hundred fifty records are inserted. No matter how carefully the hash function is designed, even if it spreads keys perfectly uniformly at random, at least one bucket is guaranteed to hold more than one record. That's not a statement about bad luck, or a poorly chosen hash function. It's a plain counting fact. It holds for any hash function at all, as long as more records go in than there are buckets to receive them.
Theorem - Simple Form
More Items Than Containers
The principle is named for a homely image. Pigeons settling into the pigeonholes of a mail sorting cabinet. But the statement is about any items, sorted into any containers. If n items are placed into m containers, and n is greater than m, then at least one container holds more than one item. The proof is by contradiction. Suppose instead that every one of the m containers holds at most one item. Then the total number of items is at most m times one, which is m. But n items were placed in total, and n is greater than m. So the total is at most m, and also greater than m, which is impossible. So the assumption was false. Some container holds more than one item.
Back to the Hash Table
A Collision Exists - Somewhere
Apply that to the opening scenario. The one hundred fifty records are the items, and the one hundred buckets are the containers. Since one hundred fifty is greater than one hundred, some bucket receives more than one record. That's a hash collision, however the hashing is done. But notice what the principle doesn't say. It guarantees a collision exists somewhere. It says nothing about which bucket. And it says nothing about how many records share that bucket, beyond more than one. The generalized form sharpens exactly that second point.
Theorem - Generalized Form
A Numeric Floor on the Fullest Container
The simple form only promises more than one, which is a weak guarantee once n is much larger than m. The generalized version gives a numeric floor on how full the fullest container must be. It uses the ceiling function. The ceiling of x is the smallest integer greater than or equal to x. So the ceiling of four point one is five, and the ceiling of four is just four. Here's the generalized principle. If n items are placed into m containers, then at least one container holds at least the ceiling of n over m items. Unlike the simple form, that floor grows with how much n exceeds m.
Proof - By Contradiction
Every Container Under the Floor?
The proof is again by contradiction. Suppose every container holds at most the ceiling of n over m, minus one items. The ceiling of any number is less than that number plus one. So the ceiling of n over m, minus one, is less than n over m. Then the total across all m containers is at most m times that, which is less than m times n over m. And that's just n. So the total is strictly less than n. But all n items were placed somewhere, so the total is exactly n. That's a contradiction. So some container must hold at least the ceiling of n over m items.
Worked Example 1
41 Records, 10 Buckets
Here's a worked example. A hash table has ten buckets, and forty-one records are inserted. What's the fewest records the busiest bucket is guaranteed to hold? Apply the generalized form directly. The ceiling of forty-one over ten is the ceiling of four point one, which is five. So at least one bucket is guaranteed to hold at least five records. And that bound is tight. The records can be spread as nine buckets holding four each, and one bucket holding five. So no bucket ever needs to reach six. The picture shows that most even spread. The dashed line marks four per bucket. Ten buckets at four each hold only forty, one short of forty-one. So keeping every bucket at four or below is impossible. The forty-first record, shown in red, forces one bucket up to five.
Checking in Code
The Same Bound, Computed
The same bound can be checked in code, using Python's built-in ceiling function instead of working it out by hand. With m equal to ten and n equal to forty-one, the ceiling of n over m prints five. Then the code confirms the contradiction step. If every bucket held at most four, the most they could hold together is ten times four, which is forty. And forty is less than forty-one, so the check prints true. No such spread exists.
Worked Example 2
Socks in a Dark Drawer
Now a classic. A drawer contains socks in four colors, unsorted. It's too dark to tell the colors apart, except by pulling socks out and comparing them. What's the minimum number of socks that must be pulled, to guarantee at least one matching pair? Treat the four colors as containers, and each sock pulled as an item. Pulling four socks isn't enough to guarantee a match. It's entirely possible to pull exactly one sock of each color, with no repeats at all. But a fifth sock forces a repeat. With five socks and four colors, five is greater than four, so the simple principle guarantees some color is repeated. The answer is five socks.
Shared Birthdays
A Guarantee, Not a Probability
Shared birthdays make a second classic example. It's a guarantee, not a probability. Treat each of the three hundred sixty-six possible birthdays, allowing for February twenty-ninth, as a container. Then a group of three hundred sixty-seven people is guaranteed to contain two people with the same birthday. That's a certainty, probability exactly one. This number is often confused with the famous birthday paradox, which asks a different question. How many people are needed before a shared birthday becomes more likely than not? The answer to that is only about twenty-three. But it comes from a probability computation, covered elsewhere in this chapter, not from the pigeonhole principle. The pigeonhole principle only ever produces certainties, usually at the cost of needing a much larger group. And in cryptography, the birthday attack on hash functions is named for that same probabilistic reasoning. It finds a likely collision far sooner than the pigeonhole certainty would need.
Comparison
Simple Versus Generalized
This table sets the two forms side by side. The simple form says that n greater than m forces some container to hold more than one item. The generalized form says some container holds at least the ceiling of n over m. The simple form guarantees a repeat exists, with no numeric floor beyond that. The generalized form gives a floor that scales with n over m. So the extra strength matters most when n is much larger than m, and a meaningful bound on the busiest container is needed. In this section, five socks and four colors guarantee a pair. And forty-one records in ten buckets guarantee a bucket of at least five.
Takeaways
Counting Forces a Collision
To summarize. The simple pigeonhole principle says n items in m containers, with n greater than m, force some container to hold more than one item. The generalized form sharpens this to a floor, the ceiling of n over m. And that floor is tight. Items can always be spread to avoid exceeding it, but never to stay under it. Both are proved by contradiction. Assume every container stays under the bound, and the total falls short of n. Guaranteed hash collisions and guaranteed shared birthdays are both certainty results. They're distinct from probability thresholds, like the birthday paradox's twenty-three. Here's something to think about. A developer has one hundred buckets and one hundred fifty items. They say pigeonhole guarantees a huge cluster that's slowing down lookups. Using the generalized form, what floor does this scenario actually guarantee? And does the developer's conclusion claim more than the theorem supports?
About Discrete Mathematics at UPI Study
Discrete Mathematics (Math 230) is a self-paced online course of 87 video lessons in 13 chapters, from logic and proof to counting, probability, graph theory and trees. It carries a NCCRS credit recommendation for 4 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus Every course with PRO →
Why take it here
Why students take Discrete Mathematics with UPI Study
Where the credit goes
Universities that work with NCCRS
Discrete Mathematics carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About The Pigeonhole Principle
What is the pigeonhole principle and how do you prove it?
How do you use the generalized pigeonhole principle to find the fullest container?
How many socks must you pull to guarantee a matching pair from a drawer with four colors?
Is the pigeonhole principle the same as the birthday paradox?
About the Discrete Mathematics course
How many college credits is Discrete Mathematics?
How much does Discrete Mathematics cost and what is included?
Which universities accept UPI Study credits?
How long does Discrete Mathematics take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 4 credits in Discrete Mathematics.
87 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
4 credits · NCCRSEnroll →