Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dynamic Perfect Hashing By: Tomer Shlomi Dynamic Perfect Hashing: Upper and Lower Bounds – Martin Dietzfelbinger, Anna Karlin, Kurt Mehlhorn, Friedhelm.

Similar presentations


Presentation on theme: "Dynamic Perfect Hashing By: Tomer Shlomi Dynamic Perfect Hashing: Upper and Lower Bounds – Martin Dietzfelbinger, Anna Karlin, Kurt Mehlhorn, Friedhelm."— Presentation transcript:

1 Dynamic Perfect Hashing By: Tomer Shlomi Dynamic Perfect Hashing: Upper and Lower Bounds – Martin Dietzfelbinger, Anna Karlin, Kurt Mehlhorn, Friedhelm Meyer Auf Der Heide, Hans Rohnert and Robert E. Tarjan

2 U={0,1,…,N-1} S  U Lookup(S,x) – Returns true if S contains x. Construct data structure in O(n) amortized time. Lookup() takes O(1) time in the worse case. Perfect Hashing

3 K=2 T[0] T[1] T[2] T[3] T[4] T[5] b 0 =1k 0 =115 b 4 =2k 4 =152 Perfect Hashing Hash functions: h k =(kx mode p) mod s

4 Dynamic Perfect Hashing Insert(S,x) – insert a new element to S Delete(S,x) – delete an element from S Insert() and Delete will take time O(1) amortized while Lookup(S,x) remains in O(1) worse case !

5 Procedure Insert(x) Count = Count + 1; If (Count > M) then RehashAll(x) else j = h(x); If (Position h j (x) of subtable T j contains x) then if (x is marked “deleted”) then remove the tag; else do nothing; else b j = b j + 1;

6 If (b j <= m j ) then If position h j (x) of T j is empty then store x in position h j (x) of T j ; else ReArrange(j, x); Else m j = 2 * max{1,m j }; s j = 2*m j (m j -1); if (condition (**) is still satisfied) then Allocate s j cells for T j ; ReArrange(j, x); else RehashAll(x);

7 Procedure ReArrange(j, x) Put all non deleted elements of T j in List L j ; Append x to list L j ; b j = length of L j ; Repeat h j = randomly chosen function in H sj ; Until h j is injective on the elements of L j ; For all y on list L j, store y in position h j (y) of T j ;

8 Procedure RehashAll(x) Put all non deleted elements of T in list L; If (x in U) then append x to L; Count = length of list L; M = (1+c)max{Count, 4}; Repeat h=randomly chosen function in H s(M) For all j<s(M) do form a list L j for h(x) = j, b j = length of L j, m j = 2b j, s j = 2m j (m j -1) Until condition (**) is satisfied; For all j<s(M) do Allocate space s j for subtable T j ; Repeat h j = randomly chosen function in H sj ; Until h j is injective on the elements of list L j ; For all x on list L j store x in position h j (x) of T j ; `12

9 Procedure Delete(x) count=count+1 j=h(x); if position h(x) of subtable Tj contains x them mark x as “deleted” else return(x is not a member of S); if (count>=M) then RehashAll(-1)

10 Procedure Lookup(x) j=h(x); if (position h(x) of subtable Tj contains x (not deleted)) them return(x is a member of S) else return(x is not a member of S);

11 Lemma – phase space The memory space used during a phase that starts with n keys being stored in the dictionary is O(n).

12 Lemma – phase time The expected time for a phase that starts with n keys being stored in the dictionary is O(n). Claim: Assume a hash function hj is chosen for Tj at the beginning or in the course of a subphase. Then the probability that hj stays in use until the end of the subphase exceeds ½.

13 Lemma – not so many phases a. With probability exceeding ½ we have: b. If the inequality in (a) is satisfied for the level-1 function h chosen at the beginning of the phase, then the phase ends with the variable count reaching M.

14 Lemma – c*n updates time Suppose that RehashAll is called at a time when n  1 keys are stored in the dictionary. Then the (expected) time needed until the first call the RehashAll after c*n updates have been performed is O(n).

15 X-Fast Trie U={1,…,M} S  U|S| = N Member(x) – if x  S return true Successor(x) – the smallest element in S that is bigger than x Predecessor(x) – the biggest element in S that is smaller than x All operations in O(Log(Log M)) time worse case. Total space of O(NLogM). The space can be reduced to O(N) in Y- Fast Trie.

16 Dynamic X-Fast Trie Insert(x) – Add element to S Delete(x) – Delete an element from S Insert() and Delete() in O(LogM) expected amortized time. Member() in O(1) worse case. Successor() and Predecessor() in O(Log(Log M)) time worse case. Total space of O(NLogM).

17 Dynamic X-Fast Trie example 010101100111 1011 0 0 0 0 1 1 1 1 1 1 1 {0,1} {010,011,101} {01,10} {0101,0110, 0111,1011}


Download ppt "Dynamic Perfect Hashing By: Tomer Shlomi Dynamic Perfect Hashing: Upper and Lower Bounds – Martin Dietzfelbinger, Anna Karlin, Kurt Mehlhorn, Friedhelm."

Similar presentations


Ads by Google