数据库课上老师提出的问题,大意是给一个集合S,给一个散列函数和相应的散列表,长为m,从S映射到表,问 使得给一个x,通过散列表判断其不在S中的概率小于0.05,这个m该是多少?
老师说这个问题是美国大学生都会证的问题,这也是中国大学生研究生缺乏的思考能力。
我完全没头绪。。只是在想这跟m有什么关系,下课后也没找到合适的资料。这里整理一下我查到的一些关于哈希表的长度设定问题的英文资料和机翻。
想看知识点的直接翻到最后即可。
USCD_EDU
http://cseweb.ucsd.edu/~kube/cls/100/Lectures/lec16/lec16-8.html
Hash table size
-
By “size” of the hash table we mean how many slots or buckets it has [ 哈希表的“大小”是指它有多少个槽或桶]
-
Choice of hash table size depends in part on choice of hash function, and collision resolution strategy [ 散列表大小的选择部分取决于散列函数的选择和冲突解决策略]
-
But a good general “rule of thumb” is: [ 但一个好的一般“经验法则”是:]
The hash table should be an array with length about 1.3 times the maximum number of keys that will actually be in the table, and [ 哈希表应该是一个数组,其长度约为表中实际存在的最大键数的1.3倍] -
Size of hash table array should be a prime number [ 哈希表数组的大小应该是素数]
-
So, let M = the next prime larger than 1.3 times the number of keys you will want to store in the table, and create the table as an array of length M [ 因此,让M =下