1 / 29

Dynamic trees (Steator and Tarjan 83)

This text introduces dynamic trees and the operations that can be performed on them, such as finding roots, adding and finding costs, linking and cutting, and more. It also discusses path decomposition, splicing, and the analysis of these operations.

nbarrett
Télécharger la présentation

Dynamic trees (Steator and Tarjan 83)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dynamic trees (Steator and Tarjan 83)

  2. Operations that we do on the trees Maketree(v) w = findroot(v) (v,c) = mincost(v) addcost(v,c) link(v,w,r(v,w)) cut(v) findcost(v)

  3. a b c d e f Lets start with paths Assume for a moment that each tree T in the forest is a path. Lets represent each path with a balanced binary search tree. d b e f e a c a b c d

  4. Findroot(v) Go up to the root and then down on the leftmost path

  5. 1 4 3 2 7 a b c d e f Mincost(v) With every vertex x we record cost(x) = the cost of the edge (x,p(x)) We also record with each vertex x mincost(x) = minimum of cost(y) over all descendants y of x. 7,1 d 3,1 4,4 b e 1,1 2,2 f e a c a b c d

  6. Mincost(p) Go down from the root following the minimum cost, when there are ties prefer a right child.

  7. 1 4 3 2 7 a b c d e f Addcost(p,c) Rather than storing cost(x) and mincost(x) we will store cost(x) = cost(x) - cost(p(x)) min(x) = cost(x) - mincost(x) Addcost(p,c) : Increase cost(x) of the root by c 7,7,6 d 3,-4,2 4,-3,0 b e 1,-2,0 2,-1,0 f e a c a b c d

  8. 3 1 4 3 2 7 7,7,6 d a b c d e f 8,8,7 3,-4,2 4,-3,0 h b e 2,-6,0 1,-2,0 2,-1,0 f e i g a c g h a b c d Link(p,q,c), cut(v) Translates directly into catenation and split of binary search trees 8 1 i h g

  9. 3 1 4 3 2 7 a b c d e f Link(p,q,c), cut(v) Translate directly into catenation and split of binary search trees 8 1 i h g 7,7,6 d 3,-4,2 4,-3,0 b e 8,8,7 1,-2,0 2,-1,0 f e h a c 2,-6,0 i a b g c d g h

  10. 3 1 4 3 2 7 a b c d e f i Link(p,q,c), cut(v) Translate directly into catenation and split of binary search trees 8 1 i h g 7,7,6 d 3,-4,2 4,-3,0 b e 8,8,7 1,-2,0 2,-1,0 f e h a c 2,-6,0 i a b g c d g h

  11. 3 1 4 3 2 7 a b c d e f 8,5,7 i Link(p,q,c), cut(v) Translate directly into catenation and split of binary search trees 8 1 i h g 7,7,6 d 3,-4,2 4,-3,0 3,0,1 b e 8,8,7 1,-2,0 2,-1,0 f e h a c 2,-6,0 i a b g c d g h

  12. Rebalancing We have to update cost(x) and min(x) through rotations w v v C A w b b B C A B cost’(v) = cost(v) + cost(w) cost’(w) = -cost(v) cost’(b) = cost(v) + cost(b)

  13. Update min: w v v C A w b b B C A B min’(w) = max{0, min(b) - cost’(b), min(c) - cost(c)} min’(v) = max{0, min(a) - cost(a), min’(w) - cost’(w)}

  14. 3,3,2 1 4 7 3 2 b a b c d e f 7,4,5 3,0,1 d 2,-5,0 8,5,7 4,-3,0 i i 1,-2,0 h e a c 2,-6,0 f e i a b g c d g h 8 1 3 i h g 7,7,6 d 3,-4,2 4,-3,0 3,0,1 b e 8,5,7 2,-1,0 f e 1,-2,0 h a c 2,-6,0 i a b g c d g h

  15. Operations that we can do on paths w = findroot(v) (v,c) = mincost(p) addcost(p,c) link(p,q,c) (p,q,c) = cut(v) findcost(v)

  16. d f g i l j Actual tree a b c e h k p q m n o r s t u v w

  17. f d i g j l Path decomposition a Partition T into disjoint paths b c Represent the paths as before e h k p q m n o r s t For each root of a path keep its “dashed” parent and the cost of the dashed edge u v w

  18. a b c d d f f e g i i g h l j j l k p q m n o r s t u v w Change the path decomposition via Splicing a Splice(p)  b c p e p h k p q m n o r s t u v w

  19. a a b c b e c h f f f d d d e k i i g i g g p q a m n o h j j l j l l b r s c k t p q m e n o u h v r s k w p q m t n o r s u t v u v w w Expose(v): Put v and the root on the same path expose(v) 

  20. Tree operations We can do them via the path operations and expose: findroot(v) : findrootp(expose(v)) mincost(v) : mincostp(expose(v)) addcost(v) : addcostp(expose(v)) link(v,w,c) : linkp(path(v),expose(w),c)

  21. e r g v v g g m d j j w m m z t r r s s u s t t u u Link (example) e r g m d w z t u s

  22. Tree operations We can do them via the path operations and expose: findroot(v) : findrootp(expose(v)) mincost(v) : mincostp(expose(v)) addcost(v) : addcostp(expose(v)) link(v,w,c) : linkp(path(v),expose(w),c) cut(v) : cutp(expose(v))

  23. a b c f d d f e i g i g h j l l j k p q m n o r s t u v w Cut (example) Cut(h)  a b c e h k p q m n o r s t u v w

  24. Tree operations We can do them via the path operations and expose: findroot(v) : findrootp(expose(v)) mincost(v) : mincostp(expose(v)) addcost(v) : addcostp(expose(v)) link(v,w,c) : linkp(path(v),expose(w),c) cut(v) : cutp(expose(v)) findcost(v) : findcostp(expose(v))

  25. Analysis Expose may do many splices  Cost of expose may be large ? But on average it will be ok. We will show that in a sequence of m operations we will not do more then O(mlogn) splices This gives an overall time bound of O(mlog2n)

  26. Analysis (Cont) Define an edge (v, p(v)) as heavy if size(v) > size(p(v))/2, the edge is light otherwise •  • At most one heavy edge enters any vertex • At most log n light edges on any path

  27. d f g i j l Heavy Heavy Example a b c e h k p m n o r s t u v w

  28. Define the splice to be heavy/light according to the type of the dashed edge which turns to be solid • Count separately light and heavy splices • No more than O(mlog n) light splices • How many heavy splices ?

  29. Bound on the number of dashed heavy edges • A link cannot create any • A cut may create at most log n • A light splice may create 1 • An expose may create 1  O(mlog n)

More Related