hash tables
如图所示,使用一个hash function将原来的key映射到hash表中。碰撞发生在不同的key映射到了同一个位置。
hash function
division method
h(k)=kmodm
multiplication method
Universal hashing
选择一组hash函数,这个组合称为 universal 如果对于每个hash函数来说,它碰撞的概率小于 |h|/m 也就是说,整体的碰撞的概率小于1/m,m是hash后的空间集合的元素个数。
In universal hashing, at the beginning of execution we select the hash function at random from a carefully designed class of functions.
在universal hashing中,从一组精神设计的hash function中选择。
Theorem
假设从一组hash函数的universal collection随机挑选了一个hash函数
h
,并且hash n keys into a table T of size m。如果k不在table中,那么
这个结果是不依赖于hash函数的选择的,也就是说,当碰撞的时候采取chaining的方法,那么当hash一个k到表中时,当它不在表中,它在的slot的 长度的平均值 是 n/m,如果k在表中是 1 + n/m(就是1 + 不在的平均长度)
it has now become impossible for an adversary to pick a sequence of operations that forces the worst-case running time. By cleverly randomizing the choice of hash function at run time, we guarantee that we can process every sequence of operations with a good average-case running time.