Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

F ne

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

Hash Jable Hash map


daa ttuctuee that 64ores keys and itt
asouated Values by uting hash tunchen.
Hach Function HCK)
weed to trans fom hey iote the indor oft hathee
2. wo paut ’ Hash code compreron fun chon
didon mem cd, mAD
3. Chaacteriches of Good hast bo.
+ Minimige olltnon
Pary and quich to ompue
Distibnte. hey values evenly in hauh table
Hare high load factor for giren serot kays
- No, of ejenent in hashtsle
Load bacor
Harh toable &ie
Col liion
Hash bnetion napd tso reords in same locahon
of Hah tabje is caled collnon
Colliion Recoluion kehnigues

Sepaate chaining Open Addrening


nea adrahe Double
Prolaing frobing Hahing
Sepaae chaining
When two or more recorde hash to same locatien in
Lash tede,fhece neeoros Stored in o Angy LinkedLat
Called a chaun.
nbie 22 hck) = kZio
Exámple

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

h (56) =56.o= 6 Lcollinon)


6

Open Addreccing Ceced Htashing


|. A keyt aee tored hash tasle iteef
2. ollieion resolved by pro bing
Lioeae prebing ocahon
Ih a iocationisoccupied, check hor new
toy rehathing
2. reth CK) =(hck) t i)7, Tas lesí2e
Example
20
rehash (too) -(b Cioo) +| ) 7
=Cloox lo)+)X 7 (oo
2 22 Uutein
rebash (56)(5620) ttl) 7 3

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

rehach (4) h, (91) = 9iz. I| =3

nehach (4) =3 + I*1).I| = o


re 2
hash (4) =3+
2*1]2l= I72 12
58 25

257.1| =3 rhash (25) = h (25) = 25 2\| = 3


hac25) 7- (2s 1.7)
rehesh (25) =[3+ |*3] =7-4 =3
=6
Trast 3+2*3]zL=9
þrebing ->i 20, 3o3, qo7, 409.312
Hach Table si2e - l00
Variants oh Lineaa probing
I. Hashing weing bucket
IH all ows mipe key elements to map to
same hah al e. EQch locaHon alows torage
o mwhpe elenents
DisadvenBags: Cotlisien ill
buctet ae
Exomple Locahon 2 4 5 6
C
Key F

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

Direetony Cgd=1) bucket Cld=l)


4 12,32,16
I,5 21, 3

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

Dine chony (gol=) Tncat l64,6

Buckat oCld 1) Bucke+ L(ld )

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)

4 Cioo) 31(u) 6Cro)


24 ( tlbo 20(1otoo 7(ooll) 22C|e{lo
9(01001 |(o(opo
26 CIioio)-ful
ldcgo buckat
Spit
dirachory Cqdr3)

Bactta BucketT tBucpetZ Bucet


ld=3)
(olo lo Io)
Cd
( Cloooo 4 Cioo) 31(H|||D
20(l oco 20Celod) 7(oo|1) 22Ctotlo)
9(oool)

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

You might also like