Download as pdf
Download as pdf
You are on page 1of 23
! ’ | A aietioneny ts defined as a gprevel purpose \=1 ee eg PaaS lat stuckue By Storing @ group of abjects. 0 chichenamies are associateal vith a set of keys and cath bey hos a Single a@ssocfabech value. wshon presented stn a bey, a dielionany will Simply Neluin dhe associated value. for example, dhe yesulb ef a elassio@m besb could be Yepresented a1 a clictionary with studens names as keys and choy scores ax dhe values. Vesults = 2 ‘sachin’ ; 1S, ‘games’: 80, ‘monish’: 40} 4 Dictionary tsa Gerwal Pperpose data shucture shot is wed for dhe stovage Pa goup of objects. * On elichionary dhe relation 01 association between dhe key anol dhe value ts lsnown as magping. Operations on clilonnyies.- # Bald or ansent - \ A maw pas oP keys and valuas i's aclded ip | tho elickonanes. * Replawe o4 yeasiyo The already eusting value dhat ts associated eit @ laey is changed or modified , | Relebe ov remove. The alreacly present element is Uninappedl Ros the obietfonany. Real oy lookup + - Rage ee The value assouated with a key is searched by passing dha. key as a seach @rgument - | i { | ¥InseCLW, > UNserlion oF elements (Key uals) ve dickionmy 0. poleke d) > Dalelion oP olemunls x Chey § velit) ue clietionay 8 Search Cxe,0)—> Gearching prescribed volun % én dhe. dicHonay D witb dhe bey ef an element 2. ‘ mamber (x, 0) Tt reluins hue P x ie dD otomise Blse. i dnplemtantaton of éhichionay Loe teagh ane & Linked Uist P sored Uist > skip list & Hashing * Tees | [> Binary, search hee Cost) [> AYc trees > Real black bee [> Splay tree. > Mutinery Search tree —> Tries, R esertotion of dictionan by ving Uinaat Us The clichionary ean be representedl 23 dhe Linsey i i Ust. The Unear List 18 dhe eallection of Pais Chey and value), Thore ave two rwthods tn Yepresentations oF dichonavies Un Unie Lisb. 4 Sorted any * Sorted chain lu gd? god dag ys la pt a zyeol FL 3 30 [we 4x The contenb of aLickionay exe always tn sorted fern. & DieHionany is @ conlaines of elements. elass Alt e Shuet node © int laey; lv value; Struct neele aneset 5 Theael : Note insert 007 Nore clelebe >: Nord printed: vat lenginc 2; besettion L & consicler, Unity dhe chictionany is empty. dhat means feast is Nove. *’ we will create @ new node with some hey ¢ value. » Plex inserting dhe new noele + becomes head nede. * Tha yede wit be cunen) and previous. key Yolus eni| previous t [te | noe * Tha neole ei! contains coment oy Previous a well Current —> wot always poinl to cunent visiting node. Previon —> wil always point 40 previous of eument node. | # af we we will want dd ensent more reoids Uke k=, Values create Such a new node. ke. N. h | a0 | nuey naw node & UWS key > Cuneo key ah So} Lathe TF Jase Fru & Again af curren} vext = row noele we wart to insert ew vetoids Ube lrey= 2 and velua=s, becomes Tb aa ae] end ey < raw okey ae Dum =nw \aals hw Sroet = 4 T]10 +a [s LJ 4 [20] nvee] Beletion.- , Te shs|- [alee] bore ‘ewer | | | IF we want to deleke middle node oP dhe ust. Ba eraraple Fhe node wit dho rey Sat fel Hts] Fallse] bala Loe]noel Prev pyoxt = cunent >next yy refatis~ +f] so[nvu] @ lease tix Oe HSE tao) no TP we wani to alelebe hea pode wih ley, eal = Uuri-pnexts delebe cow: 3s + alee I [sero OP we wani to delebe lat node with key 4 Ohe Bis hla. -eb Tehnon) Prev noxt = cunent> nook WoLL delebe cunt i fel 3 his a] 2 opel TP Coun = nucep Coutze'noda not Bund"; else | nS | 'Peeuw = head i) - head= eumnweds | else Prer > maak = cur neo ; delebe eur: | Put <*woele cloletedl | Sensching sopeletion: void dtl + Fre > | Noda acu; ink kk; | 1 \ | ain head: Coulee! entet teey chat we want to earth ANd key uoluleCcury! = NULL) & ‘Feeunent -> key ==) t Cout cNeey is found": breau; Cart = Cun —> nant; 4y 'Fecuv= never - o Cour <"clicHionary is emply" a Sku Ust xepresentation:- * A ship Ust is a dain shudure ¢hat allows Pysi Search within an ordered Seguone of elemonts . * fast search is mada possible by maintaining of Linked hueverchy of sub sepuence. x» The simplest Possible clata Shudure to suppor} Searching Us Unwed Usk. He THAD He Ley head & The time to perfaim a searth Is propotionat to the number ef noses dhat have to be enamined, cohih almost vo. ‘ie of the Skip list skip list In this example, we have 14 gram. The lower that links only Let's take an example to understand the working of the inddes, such that these nodes are divided into two layers, as shown in the diay layer is a common line that links all nodes, and the top layer is an express line 1 the main nodes, as you can sce in the diagram. Shppose you want to find 47 inthis example. You will stat the search from the first node of THe express line and continue running on the express line until you finda node that is equal a 4Y or more than 47. ou cam see in the example that 47 does nat exist in the express lie, so you seach for anode of less than 47, which is 40. Now, you goto the normal line with the help of 40, and search the 47, as shown in the diagram. iP SF cage 7 Skip List Basic Operations ‘There are the following types of operations in the skip list. Insertion operation: It is used to add a new node to a particular location in a specific ituation, yeletion operation: It is used to delete a node in a specific situation. earch Operation: The soarch ‘operation is used to search a particular node in a skip list. Txample # Create a skip list, we want to insert these following keys in the empty skip ist. 6 with level 1. 29 with level 1. 22 with level 4. 9 with level 3. 17 with level 1. 6. 4with level 2. Step 1: Insert 6 with level 1 yeep Cle ete a Step 2: Insert 29 with level 1 ker . 2 Step 3: Insert 22 with level 4 vce Step 4: Insert 9 with level 3 nae Step 6: Insert 4 with level 2 | | i | \ A | b3, 1 \dvantages of the Skip list Ifyou want to ingert a new node in the skip list, then it will insert the node very fast because thare are no rotations in the skip list. The skip list is almple to implement as compared to the hash table and the binary search trep. Itis very simple to find a node in the list because it stores the nodes in sorted form. ‘The skip list algorithm can be modified very easily in a more specific structure, such as indexable skip lists, trees, or priority queues. The skip list is a robust and reliable list. | Hashing ( @ alata Shucure dhat allows insertion and on elelehion, Searching epetation corried out in Oc) He constant average Lime. Hashing Fincting gho lovation of at felemont Gt a lata shuclure enithout mating any comparison. Moshing uses dha mattomatical Function to eleberminn dha Location of an element. i The mathematica! fiunction ealltet hash Runch’on, auepls la vellue lanows as boy as inpub anol rakes an output known as hosh ley. the hash function genzrates Vash key anal store elemonts corresponding to eacr hosh key co dhe has table. Hash table The hash tuble vs an amen ef some Fixceel sire, containing a key. A key ts assouated wit each tocol. The | insertion of dlata in the hash table ‘s based on do key ppalus hence every entiy co dho lath table is assouabed with | some KY. Hash Runction 1's ase jo Implemon) drs hosh — leables. ee-o fw. Yash foble. | Hash _feueion: soma numbet én dhe range, ¥ Gads key 18 mapped unto | © to buble sire-) and placed! ony exppopna ke cell. The mapping Ys eallledl hash Function. i | a we nese & Runction to map a key value & fo an integer index ¢ oP dhe hash table, such Renetion | | Vs called hoslung funtion. a dt ts useel to elabermine dhe Loetion of any record, giver dra hey value, Yosh Chey valus)= taeyvalur Mock Tablesire Hash(ig) = 19 mod 5 1e—y key volus. =3 5 > Tabb six | TW ley velue is is Plovedt co dhe dhiyel Location. | | | yy | | ao) Tuncation _mathoel:. | an Nugroten method trunabe dhs pert of dha. | giver lseys olopensling upon dha hash table. eg. 4grAse 4bS789 dion she hash toble ays eddies By dhe giver beys ere 456 ancl 785. | In dha methoel dhe given beys ete \roken. linto group of cigs ard add those Groups and get dha. hah table acldress. eg:- , 143765990 dhen broken these key value aa 1B groups (143)C76s) (98°) and add aterm up He sessing | Ua [388 - Ci mi squame mete | On dhs teys ane reading and to choose the middle cLigits and szuare dren to get som. nranelom laddvess to be stored tn dhs \osh boble. egy : i hsb 137 Shon Squaring dha keys 901936 18783 Inow Lae dhe a middle valu fom each gguaned values such as 74 and 1. Uy pivision. _eratels Tala dua way aspendigg “pon dha sine of dhe table, clo dhe modulus eperotion ancl get dha yemaundler. Hi- agmodte => 3. A Hash Runction assigns each valua with dhe pn guest bey. Sometime hosh ‘table uses an timper feet hash Runetion dhat couses @ collision because dhe hosh Pinediin gesotes dhe same ley of devo cuffrent values. | Wash is tneFFetent ewhen ghere axe many collisi Sions.: | tosh collision ate practically not be avoideat for lage seb af possible leys- Yash eloer not allow null values. | Two Aiferent veeids are tndicabed bo be stored laa ato game position to dhe hash table. Thi situation *S hen nud as collision. collision is cho one of dhe elementory problems ‘associabeck atte hashing. several collision resolubion bechnigues ene used to Overcome dh problem. | # Seperate Chaining % Open audleliessing » Rehashing * Gxtendible lashing D separate, chaining In dha bechnigue , @ Lnkect Lit is createct fiom dhe slot th whith collision hos occured, afbey whieh oho naw bey 18 inserbecl into dhe Linked Uist. Tha Uinteesl ust oP slots Looks Like a chain, so it is called Separate chaining | Suppose we want to tnseit dhe keys as (b,26,36 ‘phen lomod to = 6, abmoclio = & anol 36modio=b, hore every lemon ave to be placed in sho same lowtion. To Avorebing dua taint ef epllision we are using separabe chaining method R avoiding dh Linked Uist ere to be wed. all dhe fonys dhak yesolve to dhe samo hath value are maintained in a Linkesl List - o tl EERE | Hao | 7 | : whenever & Collision occurs tha bey value Us ladded ef dhe end oF dhe eoviespondiing Linkedl Uist: each position Lo dhe hash table acd as dha header node fev a linkel Usk. ito perfor dha search operation gho Usk endleateat by dhe hash Funetion ts searched segusntially- Hope atte Tix oper adliessing is collision sesolution mathodl rat 1s wsedl to contol dha collision to dhe hashing table. Ittwre (sto ley stored oubicle of dhe hah toble. there fere, bho sine of dha hash toble 1s alwoys greater dhan ov equal to the number of keys. at is also calleat closed hashing - The clisealuantages ef using separabe chaining is Hat 1¥ adds dhe ef everhosd of maintaining munttiple Unked! isk. To overcome chase gho open addressing ean be useel - open. laaiakyessing othoiwise calledl @s Lushing eothout Linked Uist. A bloue of menoy space ts Yeserved i storing dhe Nosh value do ease of collision, altumnative Lowrtions are auessed until an empty Lotion is found. ‘Th, oper aoldressing can be rontioneal as | | 2 Linear _ probing i In Liar probing Fa's ts a Uneat fundion of c, ghot means alternative loeatons are semehel wv @ Sequsotial manner, | Rael | step sbep2 skp skp 4 steps index] value] [index] value] [index] value] [Index| value] [index] value [o 9 2 [as o | s} Le | 4s Hae 1 1 13] ss TBE sel [2 2 2 2 2 | 69 1 | 3 3 3 3 3 Poteet? {s 5 5 5 5 16 6 6 6 6 i soa To BG i2 ie 8. [18 8 [18 8 | is ie | 24 9 | 39 ES 3 | sa 2 | 8 | | The position of dha key can be Pounel \ oy seguentially seatched to all positions dhot can be storting Ror dha position caleulabed by dro hash fundion until an \ i el. 1 $3918.49, 52645 empty cell ts foun eg: £34) | The teoy value W 34, (sa) = 89 Z10 . =4, 1 ill be mapped co dhe” position ‘of dho hash tables. | | beoy value =18 Cle) = 18 mod to =e dion it uoill be ‘mapped! cn cra a” position ‘of dha hash tables. Step 3'- | bay valu = 44 WES) = 49 mod to =4 04 will be mapped on dhe af position of the hash buble. sine it is alveady mapped chen it vit search for dha mnaxt free spate ushich 1S Ov position 0 oF hosh table. Blepa: bepy value = 38 | (3) = 39 mod to bho hah table. isbep 5 *- boy value = b3 WGA) = 6% moe Lo =4 hee 40,1 ae Atreadly Ocupredl dhen tt il semch Bi nod ffee space dhat din 24 postion ra hash buble. Lineot probing is @ ash bechuiguos 1's lanown te be dhe easiest aay bo resolve any collision io hash. [ables sequantial search can be perfermed to find any leallnton dha Oeeureel, - | =8, hwie 2,30 positions axe alyeadly mappeal thon ¢hab co be searched fos cho rose’ fee spate of 1t'n Ge WD uoevatie probing ‘hd Quaolvatic probing is an epen adlaliessing \ i ision € h t ogia mnun fon yesolving hash collision eo has in computer pt g 3 tables. Skepr gbepa. Skp3 sep} steps index] value] [index] value] [index] value] [index] value] [index] value 0 0 o | 49 o | 4g o | 4g 1 1 1 1 1 2 2 2 2_| sz] | 3 3 3 3 3 | 4g 4 4 4 4 4 5 3 5 5 5 6 6 6 6 6 7 7 7 z 7 s 8 118 8 | 18 8 lig a | is 9 | 89 9 | 89 9 | 83 9 | sg 9 | 34 one of dhe elised vantages 2P Une Probing i's Hot 1 lends to dha clustering oP key values at ona place. Pa new value hashes to dha cluster dhon it requive several \berations to find dhe mock vacant Slot. To overcome di alisadvartages guadvattic prob bechnigue 's Usedl- Fa'y rs &@ Guacalie Funetfon of U. That means alternative locations are semchesl a1 @ quachatic Feunction. | Feiy = t™ | ushen Aq wolldler orto 84 dhan dhe next position | pie ur one cell euweLy - af dho noxk cell u ery chan 4a oO Plaveel on thot plow. Next s# collides a} dhe position s, dhon dhe Cell ena awey 1's med but chere also (nah element. go dhe vacant cell is found et the nosct pete ts oy auvey - GW ue ig: | Double Hashing Is a Collision resolving bechnigua Gr open Addiessed Wath ‘ables. Double hashing wes a idea oF Periains a second hash Function to key whon a colliston occas. ! The we ef guadvatic yrobing may @s well Leael 1 dhe Function oF secondary clusters. To overcome —suth Bibuotions double hashing becbnigus I's useal. Fer> = thash,Cx> then | i hash, (2) = RG mod R) whore ® vs tre prime number smatter than | toble are. In our exemple 89 G moppecl ttn dhe position [4 and 18 & mappecl into dhe position s. 44 G mappecl do dha position 4 sine aheady mapped. a+ will seacle Pr dha wet cell by using dhe Falowsieg formula Mash, 49) =? - (49 mod 1) | = elitane, so dhe 49 U tnappeel on dhe ig? position. The asuantage of dsuble hashing ts Phat His one of dho best fox of Probing, proclucing @ uniform guibibution of records dhroughouk a hash tables. [ethan | Rehashing is a bechnigue ¢hat dynamically expands the sim of dhe amay map ara hashtoble to maintain oho ge anal pul operations complenity a OU). Rehashing 1s dhe process oP recalulating dha hash tode Of already stored enbries ancl moving chem to @ bigges aire hash map whor dhe number oP elements ta dhe map euches dhe monittum ghneshole value. when dre hash toble becomes too Ran én oper Qdldsessing dhe 8uuestive insertion eperation may consume more time to complete. Ty evcreoma gis situation dha. yehashing lechnigue sed The trigger Ra initotk rehashing are, CY udhen dha insertion epewtion fails CH) ushen dhe cluster becomes hal? Ry CH) ughen dha ho performance ge below a predefined dinesheld valus. Snpat t ; 5 Vesh Reunetion a ned xxs E] 43) re] : 7] > Rehoshing rio] hycxd= xz [ss] [3] Creole Yashig To avoid dhe Limitations such as dhe shahe hashing be Aalolvessing epavate chaining) led to peifdimance Vssuas ab Soma point in the Ha, The elynaniic hashing Crehashing) Lect bo bemporary unevallability of hash tables who dha sehashing being wed dhe extendible hashing are to be used. Jn extendible hashing dhe hash table ‘s stovecl do dhe main memory anal dhe lurkets are stoeal cn alisk. each valu tn dhe Wash table is @ pointer bo a bucket cn dha secondary manoty. The host Penetion \s_ apple on the enput value to germrate the bukeb pointer and peifeim to store and shan rebriee epenations. 7 Si B16 00 Earns: (a -aare i | 10 } oO Ee | 10,18, 26 | ioe | hao = aemody furs Buckets x 8 diedory of Fur slots hos been wed bo she exbenelible hashing. % Each of cho four ALivectory slots poinh at dhs Comesponclig bucwets. | * Gach buckets stores maximum of Fouy integers. i » Tre Yh Punetion dhol cletmines dhe bucked Pointer is! hexp = ae moe. Thad means it peifermos dhe modulus of | | | | Imbelutig ef 4 on au dhe Grpul values to determine dhe bucket in usluch dhe rumber will be shoved. \ e Me value written at dhe top of dha Arectory Ys called | Global_clepts. 94 inolicates dha number of ‘right rnast | bits oP dhe input number dhai ate used to elebermine dha borget louckebs. similarly dhe valu untiten et dhe | top Of dha bucket is called Local alopth. Now let us tnserk dhe valu 6 ena 30 ‘unto dhe ebivedory then dho tesud becomes, 8, 1b ool 2) oto 9 | ou a \ bo > 10,12, 26 | Lol a | ae WS iP 7 Directory eee Buckets | The value b and 30 Would have been nserted! jin budseb 10’ but dhore Ga testicion Rx four elements [for eae bucket, dhe elivedory Ys exteneled to dlouble tn size, ® new bucket is also addled at dhe bottom La elements Form cho over Plocnigg buukebs ere tedishribubeal by using dhe hash —Ranetions hex = a med 3. | JE we want jo etend dhe itectory dren che | foi rules are to be sant. | # oF de Uwertion Ff dhe naw elemant 1s causing ovetPlow situation wn a lueket Jhon compare Tis, loeal elep Ho | with dhe urea elepth. | TF dhe Local clepth is less than dhe gil depth dhan add cho now loueket, aaiust oho pointers anal Yeolihibute dhe element. | ¥ Of dhe local capt is equal to cho global eleptn dhen expan do abitectory- Jn case oP rehashing method, ake entire hash dnble [is rehashed nto @ new tnble. Incase ef extendlible hashing | Splitting and vehashing 1S penfermedonly on a specific pation ef dha rrertoiy cluter. dh Yeduring dhe impact on dhe | performance ana availabibly ef gho overall Mashing sdeme. | Ot ensure dhot dhere is no possibility of coltiston Occurence. It can be achieveel enly when dhe set of cnpul bays re known bere hand Asa tesutt eoll'sion prevention hneasures are programatically Unluded enhile elavelopring m hob Functions. | | multiplication _methools * * o choose @ content value A such thal >o

You might also like