Disjoit Sets elemets { x, x, } X =, K Opeatios x Patitioed ito k sets (disjoit sets S, S,, K Fid-Set(x - etu set cotaiig x Uio(x,y - make a ew set by combiig the sets cotaiig x ad y (destoyig them S k 5 0 5 0 MakeSet(x - add a ew elemet x ad make it ito a sigleto set Uio(, Fid-Set( Each set is idetified by its epesetative elemet x 5 0 5 0 {,,5,,,0, } {,,,, } { } { } { } { 0,,5,,, } 5 0 5 0 Fid-Set( Fid-Set( MakeSet(
Vesio Each set is a liked list (with poite to tail List head is the epesetative Each elemet has a poite to the head {,,5,,,0, } {,,,, } { } { } { } { 0,,5,,, } 5 0 Vesio A sequece of m opeatios ca take Θ( m time fo i to m/ MakeSet(i edfo fo i to m/ Uio(i-,i edfo i- i- i- poite updates i m / i = Θ( m 0 5 5 i i- i- Vesio Fid-Set(x - tavese head poite O( MakeSet(x - ceate x O( Vesio (weighted-uio heuistic Modify Vesio by keepig tack of the size of each set ad appedig the smalle to the lage Uio(x,y - Apped S x to S y ad update head poites O( S x 5 0 Each time x s head poite is updated the size of x s set doubles A head poite has bee updated at most lg times if thee ae a total of elemets i the sets A sequece of m istuctios i which thee ae MakeSets takes time O(m + lg
Vesio Each set is a tee with paet poites oly The oot of the tee is the epesetative 0 5 0 5 {,,5,,,0, } {,,,, } { } { } { } { 0,,5,,, } Vesio FidSet(x - Tavese paet poites to each oot (till x=paet(x Wost-case is Θ( 0 5 Fid-Set( 5 0 Vesio MakeSet(x - ceate x O( Uio(x,y - Lik(FidSet(x,FidSet(y 0 5 0 O( + time fo FidSets 5 Uio(, 0 Vesio (weighted-uio ad path compessio MakeSet(x Uio(x,y p(x x FidSet(x ak(x 0 FidSet(y Lik(x,y if Lik(, if ak(x>ak(y FidSet(x the p(y x if x p(x else p(x y the p(x FidSet(p(x if ak(x=ak(y etu(p(x the ak(y++ m MakeSets, FidSets, Uios at most m MakeSets, FidSets, Liks
Vesio FidSet(x - 0 5 Tavese paet poites to each oot (till x=paet(x 0 Fid-Set( 5 Let size(x be the umbe of odes i the subtee ooted at x ak(x Lemma If x is a oot, the size(x Poof: By iductio o the umbe of Lik opeatios Base: 0 Liks All odes ae oots with size ad ak 0 Step: Assume popety holds afte i Liks ad coside the Lik i+, Lik(x,y Case ak(x>ak(y (o vice vesa The ak(x does ot chage ad size(x iceases so iequality still holds Case ak(x=ak(y= The befoe the lik size(x ad size(y + Afte lik ak(y=+ ad size(y + = = ak ( y QED 5 Lemma If x p(x the ak[x]<ak[p(x] Poof: By iductio o the umbe of opeatios Base: 0 opeatios Tivially tue sice o elemets Step: Assume popety holds afte i opeatios ad coside opeatio i+ MakeSet No chage except fo ew ode with x=p(x FidSet If a ode gets a ew paet, it is the oot of its tee ad must have eve highe ak tha the pevious paet Lik The ode that gets a ew paet, gets oe with highe ak QED Lemma Fo ay 0, the # of odes of ak is at most Poof: A ode gets ak as the esult of a Lik of two tees of ak - This ode will have size at least at that time No ode ca cotibute moe tha oce to a ak chage fom - to Sice thee ae odes, at most odes ca attai ak QED Coollay Fo ay ode x, ak( x lg
Fist ty at boudig cost of m istuctios x Maximum cost of a FidSetis O(lg A sequece of m opeatios costs at most O(m lg Ove estimate sice FidSets ae destuctive, educig height of tees Caot fid sequece with Ω(m FidSets each with cost Ω(lg Idea: Boud umbe of paet updates (as i Vesio Befoe FidSet(x Idea: Combie fist ad secod appoaches Thid ty at boudig cost of m istuctios x Afte FidSet(x Chage some paet updates to the ode ad the est to the opeatio Secod ty at boudig cost of m istuctios How may times ca ode x of ak get a ew paet? At most lg - times (Its paets icease i ak fom + to lg The cost of FidSets is at most O(m + # of paet updates lg lg lg # paet updates (lg lg = 0 = 0 = 0 lg + lg lg lg lg lg + lg + = Θ( lg Cost of m opeatios is O(m + lg Ove estimate! Not may baches with cosecutive aks Caot fid Ω( odes with Ω(lg paet updates ak f (k = lg lg - f (i f (i-+ 5 f (0 = 0 f (- = - goup k i 0 goup i has aks i the age [f (i-+, f (i] f ( to be detemied 0
Amotized Aalysis usig Aggegate Method If FidSettaveses odes x, x, K, x p the the cost fo tavesig x is chaged to the ode if x ad p(x ae i the same ak goup (befoe ad p(x is ot the oot Path Chage othewise to the opeatio Block Chage Total cost = total path chages + total block chages Maximum block chages to sigle FidSetis f (lg Maximum block chages to a sequece of m opeatios is ( + m f (lg O m f ( i f ( i = ( 0 = 0 0 f f ( i = N i times f ( j = lg j + f ( i f i = f f ( i = = f ( i f ( (lg = lg (lg + = lg Total cost = total path chages + total block chages ( + m f (lg + f (lg = O( m f (lg O m ( lg O m (lg Amotized Aalysis usig Aggegate Method To boud path chages: If ode x has a paet i a diffeet goup, this will emai the case x i goup i ca be chaged at most f (i-(f (i-+ path chages Total path chages f ( i 0 = f ( i + f ( i f ( i = f ( i + f ( i f ( i ( f ( i ( f ( i + f ( i Time to choose f ( f ( i f ( i