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. 一种大气简单的Web管理(陈列)版面设计

    在页面的设计中,多版面是一种常见的设计样式.本文命名一种 这种样式.能够简单描写叙述为一行top,一列左文件夹,剩余的右下的空间为内容展示区.这种样式,便于高速定位到某项内容或功能. 在主要的HTML ...

  2. redislive

    安装Redis Live监控服务 分类: redis 2014-06-25 20:24 436人阅读 评论(0) 收藏 举报 redis redis live为监控redis服务的软件,带有监控web ...

  3. 网易2016年研发project师编程题(2)

    序 网易互联网的实习笔试立即就開始了,做几个练习题熟悉熟悉~嘿嘿~ 题目一: 小易的升级之路 小易常常沉迷于网络游戏.有一次,他在玩一个打怪升级的游戏,他的角色的初始能力值为 a.在接下来的一段时间内 ...

  4. ASP.NET MVC4空MVC项目添加脚本压缩和合并

    本文介绍的是 建立的空MVC项目如何添加该功能 1.选中MVC项目,右键>"管理解决反感的NuGet程序包" 2.在"联机"中在线搜索搜索"Op ...

  5. 移动端H5实现图片上传

    移动端H5实现图片上传 https://segmentfault.com/a/1190000010034177

  6. Atitit.虚拟机与指令系统的设计

    Atitit.虚拟机与指令系统的设计 1. 两种计算模型  ,堆栈机和状态机(基于寄存器的虚拟机1 1.1.1. 堆栈机1 1.1.2. 状态机2 2. 为什么状态机比堆栈机快呢?3 2.1. Sta ...

  7. Atitit.互联网 软件编程 数据库方面 架构 大牛 牛人 attilax总结

    Atitit.互联网 软件编程 数据库方面 架构 大牛 牛人 attilax总结 Coolshell 称号.理论与c++ 阮一峰:: 理论高手与js高手 王银:理论高手 赵劼,网名老赵,c#高手 与理 ...

  8. RGB格式等比例缩放

    原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置. /* lrgb: input 24bits rgb buffer srgb: output 24bits rgb buffer wid ...

  9. IE6下css常见bug处理

    1.双倍边距 如下图所示,一个样式里面既设定了“float:left:”又有“margin-left:100px:”的情况,就呈现了双倍情况.如外边距设置为100px, 而左侧则呈现出200px,解决 ...

  10. 分分钟学会一门语言之Python篇

    转自:http://www.code123.cc/1049.html Python 是 90 年代初由 Guido Van Rossum 创立的.它是当前最流行的程序语言之一.它那纯净的语法令我一见倾 ...