Professional Documents
Culture Documents
Hashing
Hashing
3 . 47
|
Hag
Used to store and rtriene inbo a quecky al posnbu
2. DAed to peorm optimal scarch in
Com ponents e Hathing
Hash tabe 3. Colliion
ueu
2. Hash n 4: Cotimon Kesoluton lechnu 5
Exampls hach table
3
HCK) = k 1o
Keys
2 3 4 S
Solution :
20co| -NULL
h(02) 22y I0 = 2
h (3) = 3O = 3 f22NULL
h C6) = b,.o = 6
h Cioo) = 00|o = 0 (ollisio) 4
4
6t ) 7
5
Pimay custing
Lineae prebing create ong runs of 6tled
Aots indubses nent probes XtlX+2.Xt3
rednces petrormane
Quadratie probing Tas lesize. L= l,2,3,.
|: rehash Ck) (hCK) + 2)
2. Exom ple. Tabse sie |
{31 9,23,25 24 , 2 , 91
314
2/. I| - 2
13 l| 2 .rehach (I3) = 2+ ) . tl z31| =3
= 3 rehash.(25) - ( 3 + | , | = +)=4
24 1. l| = 2 rehes h (2¢) (2 +12) y| = 37.\| =3
2 . U= lo (2+ 2° t = 6 ) =6
rehachla) = +12)% Il = lc yll = l0
4+2y Il= 132 l| = 2
a+3y, I|= 182. |l = 7
2 3 255 24 9 19 1 21
2 4
lecenday luteing
Quadratic probing creates long rwn ot tled
It atfectt peformane It is tees sereec thcn prm
Double Hathing
nehash Ckey) =hek) V. Tabesige
where
2.
Example: table Si2e=l
b, Ck) = k. I| hack) = 7- (K.7)
keye 5 5&,14 391, 253
S.| = 3
l4 : 1| = 3 rehach C4) hiCl4) = l4 /|| = 3
hel4 = 7-(I4/. ) =1
Extenible Heshing
Dyaami'c minim2e oct ot rehathing.
appro aah to haw
2. Rehazhing - DAcatee the itens throughout
buchet aray . When rehohing new aLlay a
a2e to be atteast dovble the prenow i e
3. It diracory mechann.
yed teD point the bucket.
Dirgchor
6i2e eb diectory
-gobo! depth (gd) hally i=l.
Loca! dupth (Ld) for bueker
Global depa Cgd) - hor die chones
Analye dara and conveet inko binay tormat
2. Check gBobel depth and idon hfy dieLkory
3. Tokeet nd check oreaHes.
Oetouw ocelurs
ocal dup th
< globál dapth
localdep
Gobal dpm
Bucket spit Bucket split t
Diretory ex panéion.
4. Keheshing of spit buchet elemants
Elernant hashed acCRsfully
Key , 4 12, 32 , lb 5 , 21,13. loj Bucke
Size
Binauy enrertion
loo 21
|2 |3
32
Inseting
bucke
couee tetlisdon at bcket
oretows.
Directory Cgd)
Bucket o
4 Cloo)
12(loo)
32(io0o o) 21 Qo le)
3 (olol)
lo(oiolo) fll. gd= ld Pirector
expansion
Dire chory (qd =2)
Bucket o BuckeI(l =l)
(ld-2) 4 Cloo) Bucketlcp2y
lo (ololo)
12 (|oo)
32 Cicooo0) 21 ((0loi)
1b(ioooo) 13 (oloi)
gd> ld ’ Buekt
Spit
Dire chony (gd=2)
Bucket LCid-z
Buckat Buce Bueket 3
V c 2)
(ld= 2 ) q Cloo) Hofoolo)
(2 CI1oo) S Colo| )
32((ooooo) 21 Clolo)
(6Croooo)
Key t l6, 4,b, 22,24 (O,3),7, 9, 20,244 Buc ket
Si2e 3
Binay Convess ipn
Oloto 26- |o|0
4
24 |ooo 20
l6(looo o)
4 too
6(10)
22 (tolo) ull ’ gd - d ’ direcory arpanion
Directory qd =2) IaSeit
24
Bucket o
Bucke2 31
(ed= 2) 3+HH
4ltoo f22ltete TCoo
24 C1|0oo
totorore
20 (iole0) full gd- ld ’ di recto pahon,
Direchory gd=|)
oo0oOooI
Thsert 26(fu
direcher gd=3)
lo)
Buckat (d2) Buckat 3
Buclat
Cld=3)
o Bueket 2d1)
Yeaeck Hashinq
For a given set ef key alementsa peefeat
haah hncion qeneraber uniqe hach volue for
each of the key elemenk
Pee hec hash tunchon: that getea herer enter
iobo colloion .
Minimalitt peuhect heuh funchien I diatnbute
n key elemerts n docatons
R-7