CS545 Hshng hnks to Pof. Chles. Leseson Sbol-tble poble Sbol tble holdng n eods: eod ke Othe felds ontnng stellte dt Opetons on : INSR, DL, SARCH, k How should the dt stutue be ognzed? Hsh funtons Ide: Use hsh funton h to p the unvese U of ll kes nto,,, : K k k k 4 k 5 U k3 When eod to be nseted ps to n led As ouped eh ke slot s n nseted,, ollson h ps ous. t to slot of. hk hk 4 hk hk 5 hk 3 Resolvng ollsons b hnng Reods n the se slot e lnked nto lst. 49 86 5 h49 h86 h5 Anlss of hnng We ke the ssupton of sple unfo hshng: h ke k K of kes s equll lkel to be hshed to n slot of tble, ndependent of whee othe kes e hshed. Let n be the nube of kes n the tble, nd let be the nube of slots. Defne the lod fto of to be α n/ vege nube of kes pe slot. Seh ost peted te to seh fo eod wth gven ke Θ + α. ppl hsh funton nd ess slot seh the lst peted seh te Θ f α O, o equvlentl, f n O.
Choosng hsh funton he ssupton of sple unfo hshng s hd to guntee, but sevel oon tehnques tend to wok well n pte s long s the defenes n be voded. Dest: A good hsh funton should dstbute the kes unfol nto the slots of the tble. Regult n the ke dstbuton should not ffet ths unfot. Dvson ethod Assue ll kes e nteges, nd defne hk k od. Defen: Don t pk n tht hs sll dvso d. A pepondene of kes tht e onguent odulo d n dvesel ffet unfot. tee defen: If, then the hsh doesn t even depend on ll the bts of k: If k nd 6, then hk. hk Dvson ethod ontnued hk k od. Pk to be pe not too lose to powe of o nd not othewse used ponentl n the oputng envonent. Annone: Soetes, kng the tble sze pe s nonvenent. But, ths ethod s popul, lthough the net ethod we ll see s usull supeo. Multplton ethod Assue tht ll kes e nteges,, nd ou opute hs w-bt wods. Defne hk A k od w sh w, whee sh s the bt-wse ght-shft opeto nd A s n odd ntege n the nge w < A < w. Don t pk A too lose to w. Multplton odulo w s fst. he sh opeto s fst. Multplton ethod eple hk A k od w sh w Suppose tht 8 3 nd tht ou opute hs w 7-bt wods: A 7 k. 6 5 4 3 hk A Modul wheel.. 3A A Dot-podut ethod Rndozed stteg: Let be pe. Deopose ke k nto + dgts, eh wth vlue n the set,,,. ht s, let k k, k,, k, whee k <. Pk,,, whee eh s hosen ndol fo,,,. Defne h k k od. ellent n pte, but epensve to opute.
Resolvng ollsons b open ddessng No stoge s used outsde of the hsh tble tself.. he hsh funton depends on both the ke nd pobe nube: h : U,,,,,,..g. hk k+ od ; hk k+ od Insetng ke k: we hek Τhk,. If ept we nset k, thee. Othewse, we hek Τhk,. If ept we nset k, thee. Othewse, othewse et fo hk,, hk,,, hk,. Mntenne Sn the tble fo te to te, nd get d of ll of ll dues. Fndng ke k: we hek f Τhk, s ept, nd f k. If not we hek f Τhk, s ept, nd f k. If not othewse et fo hk,, hk,,, hk,. Deletng ke k Fnd t e eple wth du wh Resolvng ollsons b open ddessng - ont ple of open ddessng No stoge s used outsde of the hsh tble tself. he pobe sequene hk,, hk,,, hk, should be peutton of,,,. he tble fll up, nd deleton s dffult but not possble. Inset ke k 496:. Pobe h496, 586 33 4 ollson 48 ple of open ddessng ple of open ddessng Inset ke k 496:. Pobe h496,. Pobe h496, 586 ollson 33 4 48 Inset ke k 496:. Pobe h496,. Pobe h496,. Pobe h496, 586 33 4 496 48 nseton
ple of open ddessng Seh fo ke k 496:. Pobe h496,. Pobe h496,. Pobe h496, 586 33 4 496 48 Seh uses the se pobe sequene, tentng suessfull f t fnds the ke nd unsuessfull f t enountes n ept slot. Pobng stteges Lne pobng: Gven n odn hsh funton h k, lne pobng uses the hsh funton hk, h k + od. hs ethod, though sple, suffes fo p lusteng, whee long uns of ouped slots buld up, nesng the vege seh te. Moeove, the long uns of ouped slots tend to get longe. Pobng stteges Double hshng Gven two odn hsh funtons h k nd h k, double hshng uses the hsh funton hk, h k + h k od. hs ethod genell podues eellent esults, but h k ust be eltvel pe to. One w s to ke powe of nd desgn h k to podue onl odd nubes. Anlss of open ddessng We ke the ssupton of unfo hshng: h ke s equll lkel to hve n one of the! peuttons s ts pobe sequene. heoe. Gven n open-ddessed hsh tble wth lod fto α n/ <, the epeted nube of pobes n n unsuessful seh s t ost / α. Poof of the theoe Poof. At lest one pobe s lws neess. Wth pobblt n/, the fst pobe hts n ouped slot, nd seond pobe s neess. Wth pobblt n /, the seond pobe hts n ouped slot, nd thd pobe s neess. Wth pobblt n /, the thd pobe hts n ouped slot, et. Obseve tht n < n α fo,,, n. Poof ontnued heefoe, the epeted nube of pobes s + n + n + n L + L n + + α + α + α L + α L + α + α + α 3 + L α. α he tetbook hs oe goous poof.
Ipltons of the theoe If α s onstnt, then essng n openddessed hsh tble tkes onstnt te. If the tble s hlf full, then the epeted nube of pobes s /.5. If the tble s 9% full, then the epeted nube of pobes s /.9. A wekness of hshng Poble: Fo n hsh funton h, set of kes ests tht n use the vege ess te of hsh tble to skoket. An dves n pk ll kes fo k U : hk fo soe slot. IDA: Choose the hsh funton t ndo, ndependentl of the kes. ven f n dves n see ou ode, he o she nnot fnd bd set of kes, sne he o she doesn t know etl whh hsh funton wll be hosen. Unvesl hshng Defnton. Let U be unvese of kes, nd let H be fnte olleton of hsh funtons, eh ppng U to,,,. We s H s unvesl f fo ll, U, whee, we hve h H : h h H /. ht s, the hne of ollson between nd s / f we hoose h ndol fo H. h : h h H H Unveslt s good heoe. Let h be hsh funton hosen unfol t ndo fo unvesl set H of hsh funtons. Suppose h s used to hsh n bt kes nto the slots of tble. hen, fo gven ke, we hve #ollsons wth < n/. Poof of theoe Poof ontnued Poof. Let C be the ndo vble denotng the totl nube of ollsons of kes n wth, nd let f h h, othewse. Note: / nd C. C ke epetton of both sdes.
Poof ontnued C Lnet of epetton. ke epetton of both sdes. Poof ontnued / C /. Lnet of epetton. ke epetton of both sdes. Poof ontnued n C / ke epetton of both sdes. Lnet of epetton. /. Algeb.. RMMBR HIS! Let be pe. Deopose ke k nto + dgts, eh wth vlue n the set,,,. ht s, let k k, k,, k, whee k <. Rndozed stteg: Pk,,, whee eh s hosen ndol fo,,,. k k h od Defne. How bg s H h? H +. Dot podut, odulo Unveslt of dot-podut hsh funtons heoe. he set H h s unvesl. Poof. Suppose tht,,, nd,,, be dstnt kes. hus, the dffe n t lest one dgt poston, wlog poston. Fo how n h H do nd ollde? od. We ust hve h h, whh ples tht Poof ontnued quvlentl, we hve od o od + od whh ples tht,.
Ft fo nube theo heoe. Let be pe. Fo n z Z suh tht z, thee ests unque z Z suh tht z z od. ple: 7. z 3 4 5 6 z 4 5 3 6 We hve Bk to the poof od, nd sne, n nvese ust est, whh ples tht od. hus, fo n hoes of,,,, etl one hoe of uses nd to ollde. Poof opleted Q. How n h s use nd to ollde? A. hee e hoes fo eh of,,,, but one these e hosen, etl one hoe fo uses nd to ollde, nel od. hus, the nube of h s tht use nd to ollde s H /. Pefet hshng Gven set of n kes, onstut stt hsh tble of sze On suh tht SARCH tkes Θ te n the wost se. IDA: wolevel shee 4 3 3 wth unvesl hshng t 3 both levels. 4 6 6 5 No ollsons 6 9 t level! 86 86 4 S 4 47 h S 3 4 h 3 7 4 S 6 4 37 37 3 4 5 6 7 8 Collsons t level heoe. Let H be lss of unvesl hsh funtons fo tble of sze n. hen, f we use ndo h H to hsh n kes nto the tble, the epeted nube of ollsons s t ost /. Poof. B the defnton of unveslt, the pobblt tht gven kes n the tble ollde unde h s / /n n. Sne thee e ps of kes tht n possbl ollde, the epeted nube of ollsons s n n n <. n n No ollsons t level Cooll. he pobblt of no ollsons s t lest /. Poof. Mkov s neqult ss tht fo n nonnegtve ndo vble X, we hve PX t X/t. Applng ths neqult wth t, we fnd tht the pobblt of o oe ollsons s t ost /. hus, just b testng ndo hsh funtons n H, we ll qukl fnd one tht woks.
Anlss of stoge Fo the level- hsh tble, hoose n, nd let n be ndo vble fo the nube of kes tht hsh to slot n. B usng n slots fo the level- hsh tble S, the epeted totl stoge equed fo the two-level shee s theefoe Θ n Θ n sne the nlss s dentl to the nlss fo etton of the epeted unnng te of buket sot. Fo pobblt bound, ppl Mkov.,