https://en.wikipedia.org/wiki/Pigeonhole_principle

Sock-picking

Assume a drawer contains a mixture of black socks and blue socks, each of which can be worn on either foot, and that you are pulling a number of socks from the drawer without looking. What is the minimum number of pulled socks required to guarantee a pair of the same color? Using the pigeonhole principle, to have at least one pair of the same color (m = 2 holes, one per color) using one pigeonhole per color, you need to pull only three socks from the drawer (n = 3 items). Either you have three of one color, or, exclusively, two of one color and one of the other.

Hand-shaking

If there are n people who can shake hands with one another (where n > 1), the pigeonhole principle shows that there is always a pair of people who will shake hands with the same number of people. As the 'holes', or m, correspond to number of hands shaken, and each person can shake hands with anybody from 0 to n − 1 other people, this creates n − 1 possible holes. This is because either the '0' or the 'n − 1' hole must be empty (if one person shakes hands with everybody, it's not possible to have another person who shakes hands with nobody; likewise, if one person shakes hands with no one there cannot be a person who shakes hands with everybody). This leaves n people to be placed in at most n − 1 non-empty holes, guaranteeing duplication.

Hair-counting

We can demonstrate there must be at least two people in London with the same number of hairs on their heads as follows.[4] Since a typical human head has an average of around 150,000 hairs, it is reasonable to assume (as an upper bound) that no one has more than 1,000,000 hairs on their head (m = 1 million holes). There are more than 1,000,000 people in London (n is bigger than 1 million items). Assigning a pigeonhole to each number of hairs on a person's head, and assign people to pigeonholes according to the number of hairs on their head, there must be at least two people assigned to the same pigeonhole by the 1,000,001st assignment (because they have the same number of hairs on their heads) (or, n > m). For the average case (m = 150,000) with the constraint: fewest overlaps, there will be at most one person assigned to every pigeonhole and the 150,001st person assigned to the same pigeonhole as someone else. In the absence of this constraint, there may be empty pigeonholes because the "collision" happens before we get to the 150,001st person. The principle just proves the existence of an overlap; it says nothing of the number of overlaps (which falls under the subject of probability distribution).

There is a passing, satirical, allusion in English to this version of the principle in A History of the Athenian Society, prefixed to ""A Supplement to the Athenian Oracle: Being a Collection of the Remaining Questions and Answers in the Old Athenian Mercuries"", (Printed for Andrew Bell, London, 1710).[5] It seems that the question whether there were any two persons in the World that have an equal number of hairs on their head? had been raised in The Athenian Mercury before 1704.[6][7]

Perhaps the first written reference to the pigeonhole principle appears in 1622 in a short sentence of the Latin work Selectæ Propositiones, by the French Jesuit Jean Leurechon,[8] where he wrote "It is necessary that two men have the same number of hairs, écus, or other things, as each other."[9]

The birthday problem

The birthday problem asks, for a set of n randomly chosen people, what is the probability that some pair of them will have the same birthday? By the pigeonhole principle, if there are 367 people in the room, we know that there is at least one pair who share the same birthday, as there are only 366 possible birthdays to choose from (including February 29, if present). The birthday "paradox" refers to the result that even if the group is as small as 23 individuals, there will still be a pair of people with the same birthday with a 50% probability. While at first glance this may seem surprising, it intuitively makes sense when considering that a comparison will actually be made between every possible pair of people rather than fixing one individual and comparing them solely to the rest of the group.

https://zh.wikipedia.org/wiki/鸽巢原理

虽然鸽巢原理看起来很容易理解,但有时使用鸽巢原理会得到一些有趣的结论:

  • 比如:北京至少有两个人头发数一样多。

    • 证明:常人的头发数在15万左右,可以假定没有人有超过100万根头发,但北京人口大于100万。如果我们让每一个鸽巢对应一个头发数字,鸽子对应于人,那就变成了有大于100万只鸽子要进到至多100万个巢中。所以,可以得到“北京至少有两个人头发数一样多”的结论。

另一个例子:

  • 盒子里有10只黑袜子、12只蓝袜子,你需要拿一对同色的出来。假设你总共只能拿一次,只要3只就无法回避会拿到至少两只相同颜色的袜子,因为颜色只有两种(鸽巢只有两个),而有三只袜子(三只鸽子),从而得到“拿3只袜子出来,就能保证有一双同色”的结论。

更不直观一点的例子:

  • 有n个人(至少2人)互相握手(随意找人握),必有两人握过手的人数相同。

    • 这里,鸽巢对应于握过手人数,鸽子对应于人,每个人都可以与[0,n-1]人握过手(但0和n-1不能同时存在,因为如果一个人不和任何人握手,那就不会存在一个和所有其他人都握过手的人),所以鸽巢是n-1个。但有n个人(n只鸽子),因此证明了命题正确。

鸽巢原理经常在计算机领域得到真正的应用。比如:哈希表的重复问题(冲突)是不可避免的,因为Keys的数目总是比Indices的数目多,不管是多么高明的算法都不可能解决这个问题。这个原理,还证明任何无损压缩算法,在把一个文件变小的同时,一定有其他文件增大来辅助,否则某些信息必然会丢失。

pigeonhole principle 哈希表的重复问题(冲突)是不可避免的的更多相关文章

  1. java数据结构和算法09(哈希表)

    树的结构说得差不多了,现在我们来说说一种数据结构叫做哈希表(hash table),哈希表有是干什么用的呢?我们知道树的操作的时间复杂度通常为O(logN),那有没有更快的数据结构?当然有,那就是哈希 ...

  2. 用python实现哈希表

    哈哈,这是我第一篇博客园的博客.尝试了一下用python实现的哈希表,首先处理冲突的方法是开放地址法,冲突表达式为Hi=(H(key)+1)mod m,m为表长. #! /usr/bin/env py ...

  3. Java数据结构和算法(十三)——哈希表

    Hash表也称散列表,也有直接译作哈希表,Hash表是一种根据关键字值(key - value)而直接进行访问的数据结构.它基于数组,通过把关键字映射到数组的某个下标来加快查找速度,但是又和数组.链表 ...

  4. 开地址哈希表(Hash Table)的原理描述与冲突解决

    在开地址哈希表中,元素存放在表本身中.这对于某些依赖固定大小表的应用来说非常有用.因为不像链式哈希表在每个槽位上有一个"桶"来存储冲突的元素,所以开地址哈希表需要通过另一种方法来解 ...

  5. 哈希表(Hash Table)原理及其实现

    原理 介绍 哈希表(Hash table,也叫散列表), 是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.这个映 ...

  6. 哈希表(Hash Table)/散列表(Key-Value)

    目录 1. 哈希表的基本思想 2. 哈希表的相关基本概念 1.概念: 2.哈希表和哈希函数的标准定义: 1)冲突: 2)安全避免冲突的条件: 3)冲突不可能完全避免 4)影响冲突的因素 3. 哈希表的 ...

  7. bzoj 2761 [JLOI2011]不重复数字(哈希表)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3210  Solved: 1186[Submit][Sta ...

  8. 2761: [JLOI2011]不重复数字(哈希表)

    2761: [JLOI2011]不重复数字 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1770  Solved: 675[Submit][Stat ...

  9. 重复的DNA序列[哈希表] LeetCode.187

    所有 DNA 由一系列缩写为 A,C,G 和 T 的核苷酸组成,例如:"ACGAATTCCG".在研究 DNA 时,识别 DNA 中的重复序列有时会对研究非常有帮助. 编写一个函数 ...

随机推荐

  1. 后缀数组suffix array

    倍增算法,时间复杂度O(nlogn) sa从小到大保存相对大小的下标 理解LSD,x数组,sa数组 char s[maxn]; int sa[maxn],t[maxn],t2[maxn],c[maxn ...

  2. 【Java】Java_15 打印九九乘法表

    使用For循环嵌套即可打印九九乘法表 以下是具体代码: /** * 打印九九乘法表 */ package com.oliver.test; public class TestMultiplicatio ...

  3. 网络协议系列之三:IP

    前言 这篇博客主要对IP协议中一些基础知识点加以总结,并将书中一些晦涩难懂的部分去除了.IP地址协议是网络层中最重要的协议,IP地址协议能够对因特网上的全部设备进行唯一标识.也正由于有了IP协议,我们 ...

  4. 在Window系统中使用Redis缓存策略

    Redis是一个用的比较广泛的Key/Value的内存数据库,新浪微博.Github.StackOverflow 等大型应用中都用其作为缓存,Redis的官网为http://redis.io/. 最近 ...

  5. 【转】原生js仿jquery一些常用方法

    现在利用扩展原型的方法实现一些jquery函数: 1.显示/隐藏 ? 1 2 3 4 5 6 7 8 9 10 //hide() Object.prototype.hide = function(){ ...

  6. 解析式/推导式, 生成器 datetime 内建函数

    列表解析式(List Comprehension) 语法: [返回值 for 元素 in 可迭代对象 if 条件] 使用中括号[],内部是for循环,if条件可选. 返回一个新的列表. 列表解析式的作 ...

  7. HibernateTools实现pojo类 数据库schma mapping映射的相互转换 二

    接着上一篇博客:HibernateTools实现pojo类 数据库schma mapping映射的相互转换 思路二:由数据库表,生成Mapping映射文件和POJO类. 尽管能够实现,但个人觉着先设计 ...

  8. github桌面工具commit不了解决

    这样发现github上还是空文件,  因为要重新添加过 1.  git add -A  添加所有文件 2. git commit -m "xxx" 3.  git push -u ...

  9. 记录下push推送优化改进点

    一)自主研发的push服务的特点及优势: 1) 消息回执确认(ack); 2) 有效期推送(设置消息的有效期); 3) 精准推送(设置设备组别推送); 4) 下发任务分解(拆分任务,多进程); 5) ...

  10. 结构体成员管理AVClass AVOption之1AVClass

    AVOption用于描述结构体中的成员变量.它最主要的作用可以概括为两个字:“赋值”. 一个AVOption结构体包含了变量名称,简短的帮助,取值等信息. 所有和AVOption有关的数据都存储在AV ...