Dynamic Perfect Hashing By Tomer Shlomi Dynamic Perfect
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
Perfect Hashing 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 K=2 T[0] b 0=1 k 0=1 b 4=2 k 4=1 15 T[1] T[2] T[3] T[4] T[5] Hash functions: hk=(kx mode p) mod s 5 2
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 !
Procedure Insert(x) Count = Count + 1; If (Count > M) then Rehash. All(x) else j = h(x); If (Position hj(x) of subtable Tj contains x) then if (x is marked “deleted”) then remove the tag; else do nothing; else bj = bj + 1;
If (bj <= mj) then If position hj(x) of Tj is empty then store x in position hj(x) of Tj; else Re. Arrange(j, x); Else mj = 2 * max{1, mj}; sj = 2*mj(mj-1); if (condition (**) is still satisfied) then Allocate sj cells for Tj; Re. Arrange(j, x); else Rehash. All(x);
Procedure Re. Arrange(j, x) Put all non deleted elements of Tj in List Lj; Append x to list Lj; bj = length of Lj; Repeat hj = randomly chosen function in Hsj; Until hj is injective on the elements of Lj; For all y on list Lj, store y in position hj(y) of Tj;
Procedure Rehash. All(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 Hs(M) For all j<s(M) do form a list Lj for h(x) = j, bj = length of Lj, mj = 2 bj, sj = 2 mj(mj-1) Until condition (**) is satisfied; For all j<s(M) do Allocate space sj for subtable Tj; Repeat hj = randomly chosen function in Hsj; Until hj is injective on the elements of list Lj; For all x on list Lj store x in position hj(x) of Tj;
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 Rehash. All(-1)
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);
Lemma – phase space The memory space used during a phase that starts with n keys being stored in the dictionary is O(n).
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 ½.
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.
Lemma – c*n updates time Suppose that Rehash. All is called at a time when n 1 keys are stored in the dictionary. Then the (expected) time needed until the first call the Rehash. All after c*n updates have been performed is O(n).
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 M)) time worse case. Total space of O(NLog. M). The space can be reduced to O(N) in YFast Trie.
Dynamic X-Fast Trie Insert(x) – Add element to S Delete(x) – Delete an element from S Insert() and Delete() in O(Log. M) expected amortized time. Member() in O(1) worse case. Successor() and Predecessor() in O(Log M)) time worse case. Total space of O(NLog. M).
Dynamic X-Fast Trie example 1 0 {0, 1} 0 1 {01, 10} 0 1 1 0 {010, 011, 101} {0101, 0110, 0111, 1011} 0101 0110 1 1 0111 1 1011
- Slides: 17