Uio-Fid //4 : Preseaio for use wih he exbook Daa Srucures ad Alorihms i Java, h ediio, by M. T. Goodrich, R. Tamassia, ad M. H. Goldwasser, Wiley, 04 Uio-Fid Pariio Srucures 04 Goodrich, Tamassia, Goldwasser Uio-Fid Pariios wih Uio-Fid Operaios! makesex: Creae a sileo se coaii he eleme x ad reur he posiio sori x i his se! uioa,b : Reur he se A U B, desroyi he old A ad B! fidp: Reur he se coaii he eleme a posiio p 04 Goodrich, Tamassia, Goldwasser Uio-Fid
Uio-Fid //4 : Lis-based Implemeaio! Each se is sored i a sequece represeed wih a liked-lis! Each ode should sore a objec coaii he eleme ad a referece o he se ame 04 Goodrich, Tamassia, Goldwasser Uio-Fid Aalysis of Lis-based Represeaio! Whe doi a uio, always move elemes from he smaller se o he larer se Each ime a eleme is moved i oes o a se of size a leas double is old se Thus, a eleme ca be moved a mos Olo imes! Toal ime eeded o do uios ad fids is O lo. 04 Goodrich, Tamassia, Goldwasser Uio-Fid 4
Uio-Fid //4 : Tree-based Implemeaio! Each eleme is sored i a ode, which coais a poier o a se ame! A ode v whose se poier pois back o v is also a se ame! Each se is a ree, rooed a a ode wih a selfrefereci se poier! For example: The ses,, ad : 4 7 0 04 Goodrich, Tamassia, Goldwasser Uio-Fid Uio-Fid Operaios! To do a uio, simply make he roo of oe ree poi o he roo of he oher 0! To do a fid, follow seame poiers from he sari ode uil reachi a ode whose se-ame poier refers back o iself 0 04 Goodrich, Tamassia, Goldwasser Uio-Fid
Uio-Fid //4 : Uio-Fid Heurisic! Uio by size: Whe performi a uio, make he roo of smaller ree poi o he roo of he larer! Implies O lo ime for performi uio-fid operaios: Each ime we follow a poier, we are oi o a subree of size a leas double he size of he previous subree Thus, we will follow a mos Olo poiers for ay fid. 0 04 Goodrich, Tamassia, Goldwasser Uio-Fid 7 Uio-Fid Heurisic! Pah compressio: Afer performi a fid, compress all he poiers o he pah jus raversed so ha hey all poi o he roo 0 0! Implies O lo * ime for performi uio-fid operaios: Proof is somewha ivolved ad o i he book 04 Goodrich, Tamassia, Goldwasser Uio-Fid 4
Uio-Fid //4 : Java Implemeaio 04 Goodrich, Tamassia, Goldwasser Uio-Fid Java Implemeaio, 04 Goodrich, Tamassia, Goldwasser Uio-Fid 0
Uio-Fid //4 : Proof of lo* Amorized Time! For each ode v ha is a roo defie v o be he size of he subree rooed a v icludi v ideified a se wih he roo of is associaed ree.! We updae he size field of v each ime a se is uioed io v. Thus, if v is o a roo, he v is he lares he subree rooed a v ca be, which occurs jus before we uio v io some oher ode whose size is a leas as lare as v s.! For ay ode v, he, defie he rak of v, which we deoe as r v, as r v [lo v]:! Thus, v rv.! Also, sice here are a mos odes i he ree of v, r v [lo ], for each ode v. 04 Goodrich, Tamassia, Goldwasser Uio-Fid Proof of lo* Amorized Time! For each ode v wih pare w: r v > r w! Claim: There are a mos / s odes of rak s.! Proof: Sice r v < r w, for ay ode v wih pare w, raks are moooically icreasi as we follow pare poiers up ay ree. Thus, if r v r w for wo odes v ad w, he he odes coued i v mus be separae ad disic from he odes coued i w. If a ode v is of rak s, he v s. Therefore, sice here are a mos odes oal, here ca be a mos / s ha are of rak s. 04 Goodrich, Tamassia, Goldwasser Uio-Fid
Uio-Fid //4 : Proof of lo* Amorized Time! Defiiio: Tower of wo s fucio: i i-! Nodes v ad u are i he same rak roup if lo*rv lo*ru:! Sice he lares rak is lo, he lares rak roup is lo*lo lo* - 04 Goodrich, Tamassia, Goldwasser Uio-Fid Proof of lo* Amorized Time 4! Chare cyber-dollar per poier hop duri a fid: If w is he roo or if w is i a differe rak roup ha v, he chare he fid operaio oe cyberdollar. Oherwise w is o a roo ad v ad w are i he same rak roup, chare he ode v oe cyberdollar.! Sice here are mos lo* - rak roups, his rule uaraees ha ay fid operaio is chared a mos lo* cyber-dollars. 04 Goodrich, Tamassia, Goldwasser Uio-Fid 4 7
Uio-Fid //4 : 04 Goodrich, Tamassia, Goldwasser Uio-Fid Proof of lo* Amorized Time! Afer we chare a ode v he v will e a ew pare, which is a ode hiher up i v s ree.! The rak of v s ew pare will be reaer ha he rak of v s old pare w.! Thus, ay ode v ca be chared a mos he umber of differe raks ha are i v s rak roup.! If v is i rak roup > 0, he v ca be chared a mos -- imes before v has a pare i a hiher rak roup ad from ha poi o, v will ever be chared aai. I oher words, he oal umber, C, of cyber-dollars ha ca ever be chared o odes ca be bouded by lo* C 04 Goodrich, Tamassia, Goldwasser Uio-Fid Proof of lo* Amorized Time ed! Boudi :! Reuri o C: 0 s s s s < + + + C lo* lo* lo* lo* <