0% found this document useful (0 votes)
38 views20 pages

DSA_Unit-1_Notes

The document discusses hash functions and their application in hash tables, including the concept of collision resolution and the importance of minimizing collisions. It explains the mechanics of hash functions, such as division and multiplication methods, and their impact on key distribution within buckets. Additionally, it highlights the need for efficient handling of overflows and the conversion of keys into unique integers for effective hashing.

Uploaded by

qwertyuiop6851
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
38 views20 pages

DSA_Unit-1_Notes

The document discusses hash functions and their application in hash tables, including the concept of collision resolution and the importance of minimizing collisions. It explains the mechanics of hash functions, such as division and multiplication methods, and their impact on key distribution within buckets. Additionally, it highlights the need for efficient handling of overflows and the conversion of keys into unique integers for effective hashing.

Uploaded by

qwertyuiop6851
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 20
Class sfcome Subject ! helvasad Dubs Stouchees Ss Mgeditoms_— ; Cans 2 Coorclinadirrt MS. Shulhoda P. Mone € — : = | = Gyaupled_ of dicliracied ace Aiud io. root — -cupplicaier§, induding the spelling checker, _ Pecans +he_ inden tore on _clatabote ~Orad the _symba) tables generated by - _ leader’, assembles, and compilerk oe There ave_teo stypes__of= Ho Wing Has ti “Th stedic bashing He alichomoy a _fo_a_cuble, ht, catted te pach’ table. the posh table is _parfitined ‘te b buckets, — htfod. ee bucket js _ = _ _-copable of beldling ‘5! dlichnary poise _ Cor pointers to this mary pairs). . - —ThS, a bucket is sald te_cong'gt of 's | ___-sbt8,each slot being tasge enor ie i “gre dichonety pale gh —to_told. = Usually, S21, ond aath bulesh ca bold _ exactly one pole. ~ : — The aoldw2ts or locaton of 6 | | { is ‘k. js_cleterrm'mn2cl by at a a “pt which wep Kees into buckets” ! Cy _Definiten= the key density aa hash jah, _ fa the aati nf, _eohexe ‘yy ts the _neonbOr a ~ 88 pals inthe table auel ‘T’ 3s the dotel _ | Namber~ of _pessible keys, The loading — — —~__ density or oading Roche of x ha gh he ‘ feat ——— Example = Congdem a hash table with b=26 . ———baskels— aud s=2, Assume thot -thae® Ore. 7.2 lo_idishret Keg cool thot cach Key ‘pegtrg woth a letter, The loads Rete a, kr ——Hhis table _is_le/eo =a. =The hash function ‘hy! ynust map sthe___possible keys Into one of each one the numb e380 hia, = TF the ‘ntermod ing resendah or frx_dre_leHlen8 Ato" coneeopondd ty the ube 0 + I¢ sespeckyely, thon Hoe Function \W cleBned by nck )= She Bist chiwader of “kK will” hadh aff \eesys jnto_the hash fable .. > =the “Kome bb A2,AL AS A4 ond E€ ore 63,0, €,1) 0,-9,.0,-0 and oreap eckve = 4 mua Ay AL,A2, AS, ound Ah are | Siro ; yw 2+ 7 = 30. a axe __& ans GA+ The. Following. __-Aiguxe_shnos the keys GA, D,A,o Ad extereal nto Hre hash table, = They ot shown in_tne Ay, b iS in ___ _Sht i of fuk? 1. tet | slot : oo * 2 i — il _ Sees 4 _ : {D> | 7 4p | 7 Ss} . a _¢ | an v7 u ———.— ——— Hash table with 96 pagetsand poo SIS per = Bucket - a =Nete tat GA and @ one ins the same backe _ asad each fucket fa too slebS =Simitedy , tre_syromyms A and Ar are in _ the same buchet. the next k. pAb hoshes jytn bucket 0. This bucket’ ts RL wcket indicates thot Al iS. met inthe bucket. _ ~— An_owenflee bas now occursed 2 tego ————betretectetcte, Wher ne vert fae —ecca®, the time _wequiredl to insext, delete oy _ search us} hing di end Somes on tre Hime requiresl to compute the / hash — ——Fancher_ond the time 45 seasth_ ene, - + --_]|-_-___- —_ __=The sbwe a. 1S meh well suihecl -Qr-_rost - cical applicakens because of fre. — ees nee of allisiens avol result v9 overflows Hnat occur. @ — Haslring schemes use oa hash fuuction +5 wap Feys into. oh table buckets , aer IS desivable to ule & hash fumchion tot is both easy to compute awd inimi228 fhe, mamb2s oF collision , TSimee the size of +e key space js usually severat grderd of —rognitud — bosgers thon +he number of buckets z Since. the. yumber oF slots tn a rucket is small, a vertlews mecessaot ly ~~ 0ceuars Hence, a mechowise to hand (a —_overfiowsS is needed, Topic = Hash. Fumebions — =P hash Funckion maps a oH into o buckef Inthe hosh ete - - — the desired propethes cf sack a Lurohon — Gort Abode it be e984 +0 Compute anol ———tHhad EL aminimi2e the numb ex of collisions, =Ta_asldition,cwe wowd |jke fhe hag Function 40 be such thad~ je it do ed pof- Tew ino biased 48e of te hash table fr yondom, impuss 5 Hodis, it kis the ka. Chesen et redo He Key Space, then we wank the Probebility frat h(K) = 4! to pee alt” buckets}, -— Wi) this Shpulation, a wandom ke had oun_egu-ed aes oe haa borg ae of Hre_ buckets. A @ haoh tumetiory 7 sas fal ts propaty 1S catlid a woieten hash -Auxchon, 7 a @ : * Diyision — = : Punkon, which so Hee idel: — This hash ancien, whichis the most wi ie seal hast Aumekon in prackce, assures Hoe ~ Kees oore naman ahve jrtegers, The ae — packet ic obtaines! —by_usirg — dhe -motulo = ey AR is divdesk boy Some _umber- Dy ard the vemainderr is uged a9 +e home bucket -fine Ke Mare ermailey, he) ek Dd = —=This_funchen gives bucket addwesse3 jn the —earje 0H _D=-1, so the hosh tattle must hove ab least _b=D__buskets, Altay fore nos leey spaced, every the\ce of D rnoked ‘Wo _unifinsa posh fmchen, the number of _overttlno8 on yoo) world hichonaried ig __extically depended en the cloice 7 = TAD" is divisible by roo, hen oddf keys re _ynopp2d to edd buckets ——Cas_ the nremainderr is odd’) p-drol_ Avery : keys. acre_mappeol td Ven buckets, _ _ Since real-uwentd_ dictonarics_ _tenal to — ove 6 bi0d tmesarxd8 otter edd gr oxo ——--KeyS, the 092 of oy even divisor D — reBubeS imo _eowrespem ne bia® ‘in +the_ _DistibeBen. of heme bckols ' =a prahee, it ha8 been frend ae reo) toatl dick omar) the cee oF hemne-buckebs 1s fi oa S biases wheneror D hag Small pairs Fachors sugh 38 913,57 and G0 ON, - “fhe “howe Peake ae on _ quar Ane key avd then using an ob sua - — nam of bits Prom “tne ymiald le Qe 9 she _ Sqrore_4o obtain +he pucker _ . —addaress 5 dre _| key tc ascumed to be an_ Inte onr,, = Since_the _midille bits ef the square@ ve uSually depend on ash bits of tre coy, clifferert keys ase -Cxp ected —4p_reesult in differ’ bash gadacexed - wil Haigh 4 probability, ever when. whem seme Ee A the _cLiqgt ore fhe same, =the weber fF bits _do_be wed ty obtain ee (eet adders clepends on the ae on ae axe__ued, th 92 of — Vobue8 js So! -H sezangh W-li co fre i 2e of hosh 1,29 js chosen +o - b@ 0 power VF to when bre mid— _—— FS quasre Frnchion is_used , —# Big = em this mneHud tve_key'b/ jg Kened ~_into_sewernl_ putt ol het oaactd neers = lost. —beiney ot _fhe_ some tempts. a these. Ss Cran eT ae? oe - yogether ty obtain te _hesh oddress fox kK, — ® et woa4y. oP _cxcexy ing nd Bak an bat alah Wen ase ehifiad sothot He leash —s} wheank bie of esoh fj F 28 topes thee —casmespena bof the lost a = d =the different 1 \ sageter to (et ox gon aslel — + 'hCk), This method js Gone as— shit lding —= Tn_the_secrd_m. bee soy yd ane — posite Lewedeiet” aa dys Gat she same pesitien ome addeo! tog then 4 4a carrie ek). Tha <9.uivalert +s le caplet tthe pastibta—a.nol —__ Exommple — supp =)23203241 | |229 ; ws : it into. hod axe Hee decivnal its_lony, The pastiNend are pra =|2%, Py = 20% 224) Phe, Pe 228 using shifi Falding = Le obtein ty) = Pj= 34 20324] 4112-20 a = 653 — When 6 Bll, we fined yevers. 52 Ps nd Pato abode 302 | — One ll, sceepestvely at tee oundaaies is_used on 6) Next, 5 partion’, axe odd edd to obbaly — le) 21234302 +2420 > 999 FDigir Awolsis— This ested is palely wef in He. -Co8e of a state file copere alt the keys —in_ the table cere frown in advence . 7 = — bach Key is—jrboycpy refed! e2 a number ausieg- Some rca Me —TheSsame redlix —is_ RES yo Keys in dhe table. Using His wade, - agit of wench kay ore examin2al 7 Dyjits Roving she wort skewat cigs blac cles clots tee — Enough digits ove cleletied so that the Yamber~ of evemaining obigits is Small ee - en to gie.an_ address in tHe. eo “To use seme described hag funch'ong, keys meeol to Rash be comvertesl ty man negah ve inheqe7S. Since all hash flunchen3, hash several reyS into the same home _ _bucke#, jt iS not mecegsomy fru. to. convert keys into Unigte nema meq VO iotegens. _ = a -T+ js. 0l< for us ty convert the strives Dota, structeres , and Aritawng inte oe Some hyateg 24 Ca at @ imple — Since EIS “nek mecesary to cones _gaings. nto _umige__nn~ negahve integeeS, we ——._COng__19) even stig ,— po — nattOr fro ~ Jong, into a 16-bit tnteg2e, = alla al gesthw converts. pairs of chavackes fro _o “unique. —inbeg et eral trey Su __ fhese_umique_inteyenr$ _-N cout oauce_h oe 203 jer pb = by __g bits), ao So would a us — integeed thd ere not much more Han g bybs long. ae exam ple, Shejngs hot ome Othe —cheon.chers long _worddl__preduce int er erS_upto at _bits long. Shing by & bits __ ast us 4D _aves the entre range of incdegerd i every with string ¢ shod dere to Chaya dene he | : asp _int_S Stang Todnt Cstirg © SS a= - YY Cor Sita 0. _notn~0- in _ — tinal bi ere, ae rink 4 the Ind length =(int) lengthy number of claret” _ 7 . = ins: —unsign2el ind ansucen- =O) - aS emg Hage 2 eal)” - —— J] -\engthts_o dol — — answer = Sat | Clengtt = oy — tently =

You might also like