Dirichlet's Drawer Principle

Computer Science
Dirichlet's Drawer Principle

Have You Heard About the "Pigeonhole Principle"?

Have you ever noticed that in some systems, when you log in on one machine, you're automatically logged out from another? This behavior ensures that a user can only be logged in from one device at a time.

There's a basic mathematical concept behind this: the Pigeonhole Principle, also known as Dirichlet's Drawer Principle.

"If more than n items are placed into m containers, with n > m, then at least one container must contain two or more items."

This can be represented mathematically as:

If n > m, then ∃ k ∈ {1, ..., m} such that container k contains ≥ 2 items.

Applying this logic to user authentication: if you have 10 users, but detect 13 active sessions, then at least one user must be logged into more than one machine — which violates the uniqueness rule for logins.

Here's a simple Python example to simulate this scenario:

# Dictionary of active sessions per user
active_sessions = {
    "ana": ["machine1", "machine2"],
    "bob": ["machine1"],
    "ava": ["machine1", "machine3"],
    "dan": ["machine2"]
}

# Check if any user has multiple logins
for user, machines in active_sessions.items():
    if len(machines) > 1:
        print(f"Warning: {user} is logged in from multiple machines:
{machines}")

This principle appears in various real-world situations:

  • Meeting rooms: If there are 6 meetings scheduled but only 5 rooms, at least one room must host more than one meeting, which can help in checking for resource overallocation.
  • IP address allocation: In a network with only 40 available IPs and 50 devices, at least 10 will fail to connect.
  • Resource allocation: If a system has more processes than available licenses or memory slots, collisions and failures will occur.

Understanding and applying the Pigeonhole Principle helps in quickly identifying:

  • Lack of uniqueness where it is expected (e.g., logins, allocations);
  • Collisions in limited systems (e.g., hash tables, ports, IPs);
  • Problems with distributing limited resources fairly.

Sources and Further Reading

Related Articles

April 16, 2025

Randomized Algorithms

How algorithm randomization can be a powerful ally

Read More