hash tables
如圖所示,使用一個hash function將原來的key映射到hash表中。碰撞發生在不同的key映射到了同一個位置。
hash function
division method
multiplication method
Universal hashing
選擇一組hash函數,這個組合稱爲 universal 如果對於每個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函數
這個結果是不依賴於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.