hash table

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中,那麼 E[nh(k)] 最大是 α=n/m ,如果k在table中,那麼是 1+α

這個結果是不依賴於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.

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章