Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mergeable Trees1 Mergeable Trees Mergeable Trees Robert E. Tarjan Princeton University and HP Labs Joint work with Loukas Georgiadis, Haim Kaplan, Nira.

Similar presentations


Presentation on theme: "Mergeable Trees1 Mergeable Trees Mergeable Trees Robert E. Tarjan Princeton University and HP Labs Joint work with Loukas Georgiadis, Haim Kaplan, Nira."— Presentation transcript:

1 Mergeable Trees1 Mergeable Trees Mergeable Trees Robert E. Tarjan Princeton University and HP Labs Joint work with Loukas Georgiadis, Haim Kaplan, Nira Shafrir and Renato Werneck Partial results: Georgiadis, Tarjan, and Werneck, Design of data structures for mergeable trees, SODA 2006 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAAAAAA

2 Mergeable Trees2 Outline 1.The Problem 2.The Motivating Application 3.Dynamic Trees 4.Mergeable Trees via Dynamic Trees 5.Implicit Mergeable Trees 6.Mergeable Trees via Partition by Rank 7.Open Problems

3 Mergeable Trees3 Goal: Maintain a forest of rooted trees. Queries: parent(v) nca(v,w) root(v)

4 Mergeable Trees4 Goal: Maintain a forest of rooted trees. Queries: parent(v) nca(v,w) root(v) Trees are heap-ordered (root=smallest) Updates: insert(v) merge(v,w) : merge the v-to-root and w-to-root paths, preserving the heap order.

5 Mergeable Trees5 Goal: Maintain a forest of rooted trees. Queries: parent(v) nca(v,w) root(v) Trees are heap-ordered (root=smallest) Updates: insert(v) merge(v,w) : merge the v-to-root and w-to-root paths, preserving the heap order. Other updates: link(v,w) : make root v a child of node w in another tree = merge(v,w). cut(v) : make v a root by disconnecting from parent. delete(v) : delete leaf v = cut(v), discard v.

6 Mergeable Trees6 Example 32 674 9 11 10 1 5 8

7 Mergeable Trees7 Example merge( 5, 2 ) 3 2 674 9 11 10 1 5 8 3 2 674 9 1 8 11 10 5

8 Mergeable Trees8 Example merge( 6, 11 ) 3 2 6 7 4 9 1 8 11 10 5 32 6 74 9 1 8 11 10 5

9 Mergeable Trees9 Example merge( 6, 11 ) 3 2 6 7 4 9 1 8 11 10 5 32 674 9 1 8 11 10 5 3 2 6 7 4 9 1 8 11 10 5 merge( 7, 8 )

10 Mergeable Trees10 Mergeable Trees: Motivation Used in [Agarwal, Edelsbrunner, Harer and Wang ’04 ]; R sub-problem in their algorithm for computing the structure of 2 -manifolds embedded in R 3. nodes = critical points (minima, maxima, saddle points), heap-ordered by height.  merging is used for pairing critical points;  no cut operation;  link only attaches leaves to the tree;  the arguments of merge are always leaves.

11 Mergeable Trees11 Turbo Exhaust Manifold

12 Mergeable Trees12 1 2 3 4 6 8 9 5 7 10 Reeb Graph encodes skeleton of manifold sink ( 0 out-degree) source ( 0 in-degree) up-fork ( 1 in, 2 out) down-fork ( 2 in, 1 out) Nodes in Reeb Graph

13 Mergeable Trees13 Pairing Algorithm on Reeb Graph x x x v vw v merge(x,v) root(v) ≠ root(w): pair x with max{root(v),root(w)} root(v) = root(w): pair x with nca(v, w) merge(x,v); merge(x,w) merge(x,v) while v is paired, replace by parent(v) pair x with v sink

14 Mergeable Trees14 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 1 2 3 4 6 8 9 5 7 10 Example

15 Mergeable Trees15 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 1 2 (3) 3 (2) 4 6 8 9 5 7 10 pair(3,2) merge(3,1) merge(3,2) Example

16 Mergeable Trees16 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 1 2 (3) 3 (2) 4 6 8 9 5 7 10 merge(4,3) merge(5,4) merge(6,4) Example

17 Mergeable Trees17 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 1 2 (3) 3 (2) 4 6 8 9 5 (7) 7 (5) 10 pair(7,5) merge(7,5) Example

18 Mergeable Trees18 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 1 2 (3) 3 (2) 4 (8) 6 8 (4) 9 5 (7) 7 (5) 10 pair(8,4) merge(8,7) merge(8,6) Example

19 Mergeable Trees19 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 1 2 (3) 3 (2) 4 (8) 6 (9) 8 (4) 9 (6) 5 (7) 7 (5) 10 merge(9,8) pair(9,6) (6 is the closest unpaired ancestor of 9) Example

20 Mergeable Trees20 1 2 3 4 6 8 9 5 7 10 Reeb GraphMergeable Trees 2 (3) 3 (2) 4 (8) 6 (9) 8 (4) 9 (6) 5 (7) 7 (5) 10 merge(10,6) pair(10,1) (1 is the closest unpaired ancestor of 10) Example

21 Mergeable Trees21 Two-Pass Algorithm To avoid parent operation Pair max with min Run algorithm forward and backward Do no pairing in “sink” case

22 Mergeable Trees22 1 2 3 4 6 8 9 5 7 10 Reverse Reeb GraphMergeable Trees 2 3 4 6 8 9 5 7 10 (1) 1 (10) 10 (max) is paired with 1 (min) Reverse Pass of Two-Pass Algorithm

23 Mergeable Trees23 1 2 3 4 6 8 9 5 7 10 Reverse Reeb GraphMergeable Trees 2 3 4 6 8 9 5 7 10 (1) merge(8,9) merge(7,8) 1 (10) Reverse Pass of Two-Pass Algorithm

24 Mergeable Trees24 1 2 3 4 6 8 9 5 7 10 Reverse Reeb GraphMergeable Trees 2 3 4 6 (9) 8 9 (6) 5 7 10 (1) pair(9,6)* merge(6,8) merge(6,10) *pair 6 with root of min label; this pair is missing from forward pass. 1 (10) Reverse Pass of Two-Pass Algorithm

25 Mergeable Trees25 1 2 3 4 6 8 9 5 7 10 Reverse Reeb GraphMergeable Trees 2 3 4 6 (9) 8 9 (6) 5 (7) 7 (5) 10 (1) pair(5,7) merge(5,7) 1 (10) Reverse Pass of Two-Pass Algorithm

26 Mergeable Trees26 1 2 3 4 6 8 9 5 7 10 Reverse Reeb GraphMergeable Trees 2 3 4 (8) 6 (9) 8 (4) 9 (6) 5 (7) 7 (5) 10 (1) pair(4,8) merge(4,5) merge(4,6) 1 (10) Reverse Pass of Two-Pass Algorithm

27 Mergeable Trees27 1 2 3 4 6 8 9 5 7 10 Reverse Reeb GraphMergeable Trees 1 (10) 2 3 4 (8) 6 (9) 8 (4) 9 (6) 5 (7) 7 (5) 10 (1) merge(3,4) merge(1,3) merge(2,3) Reverse Pass of Two-Pass Algorithm

28 Mergeable Trees28 Mergeable Trees: Results n = number of nodes in merges m = number of merges O(log 2 n) amortized time per operation O(logn) amortized time without cuts O(logn) worst-case without cuts, parent queries

29 Mergeable Trees29 Dynamic Trees Goal: maintain a forest of trees with values on vertices and/or edges. Operations:  link(v,w) : add an edge between v and w. (no cycles allowed)  cut(v,w) : delete edge (v,w).  various operations (e.g. find a vertex of minimum value on a path or in a tree). Trees can be free (unrooted), rooted, or ordered. Lots of applications: network flows, static and dynamic graph algorithms, computational geometry, … Several data structures with optimal O(logn) time per operation (worst case, amortized or randomized)

30 Mergeable Trees30 Dynamic Trees Optimal Data Structures: Sleator and Tarjan (‘83, ‘85) : Link-Cut Trees – Worst Case and Amortized. Frederickson (‘85, ‘97) : Topology Trees – Worst Case. Alstrup, Holm, de Lichtenberg and Thorup (‘97, ’03) : Top Trees – Worst Case. Acar, Blelloch, Harper, Vittes and Woo (’03) : RC-Trees – Randomized. Tarjan and Werneck (‘05) : Self-Adjusting Top Trees – Amortized.

31 Mergeable Trees31 merge(w,p) : Suppose we have computed nca(w,p) and isolated the two paths to be merged. It remains to do the actual merge by changing parents. Mergeable Trees via Dynamic Trees m j g r d c a i f l b u t v s w e h k on qp

32 Mergeable Trees32 Mergeable Trees via Dynamic Trees First idea: Iterated Insertions Insert the nodes of the shorter path into the longer. (Suggested in Agarwal et al.) Cost is bounded below by the sum of the lengths of the shorter paths. Unfortunately, this is m j g r d c a i f l b u t v s w e h k on qp merge(w,p) : Suppose we have computed nca(w,p) and isolated the two paths to be merged. It remains to do the actual merge by changing parents.

33 Mergeable Trees33 Mergeable Trees via Dynamic Trees merge(w,p): Suppose we have computed nca(w,p) and isolated the two paths; it remains to do the actual merge by changing the parent pointers. m j g r d c a i f l b u t v s w e h k on qp Better idea: Interleaved Merges Cut edges where parents change and link the pieces together. Time is O(#cuts × logn).

34 Mergeable Trees34 Mergeable Trees via Dynamic Trees merge(w,p): Suppose we have computed nca(w,p) and isolated the two paths; it remains to do the actual merge by changing the parent pointers. m j g r d c a i f l b u t v s w e h k on qp To enable fast merging: Query: topmost(v,w) : return the smallest (topmost) ancestor of v strictly greater than w. (assume v>w) r Better idea: Interleaved Merges Cut edges where parents change and link the pieces together. Time is O(#cuts × logn).

35 Mergeable Trees35 Mergeable Trees via Dynamic Trees 1 2 3 1 2 3 6 7 8 9 4 5 10 11 12 13 14

36 Mergeable Trees36 Mergeable Trees via Dynamic Trees 1 2 3 4 5 1 2 3 6 7 8 9 4 5 10 11 12 13 14

37 Mergeable Trees37 Mergeable Trees via Dynamic Trees 1 2 3 4 5 6 7 8 9 1 2 3 6 7 8 9 4 5 10 11 12 13 14

38 Mergeable Trees38 Mergeable Trees via Dynamic Trees 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 6 7 8 9 4 5 10 11 12 13 14 13 14

39 Mergeable Trees39 Analysis of Merge #parent changes = O(m logn). w v Each node has parent potential (on its parent) has child potential (on its children). 1 log(v-w)

40 Mergeable Trees40 Analysis of Merge #parent changes = O(m logn). w v cut (or delete) : one parent change (to null)  Φ  1. 1 log(v-w)

41 Mergeable Trees41 Analysis of Merge #parent changes = O(m logn). w v cut (or delete) : one parent change (to null)  Φ  1. 1 log(v-w) merge(v,w) : Φ  O(logn) if v,w in different trees (initial link).

42 Mergeable Trees42 Analysis of Merge #parent changes = O(m logn). w v All other Φ changes are non-positive. 1 log(v-w) z w  z y x w w-x ≤ (w-z)/ 2  parent potential of w  1 y-z ≤ (w-z)/ 2  child potent of z  1 Pays for parent change of w.

43 Mergeable Trees43 Implicit Mergeable Trees 32 8 12 7 5 1 4 11 6109 Parents are computable but not efficiently. Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin

44 Mergeable Trees44 Implicit Mergeable Trees merge(v,w): Case (a) v,w in different trees: link(v,w) 32 8 12 7 5 1 4 11 6109 Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin

45 Mergeable Trees45 Implicit Mergeable Trees 32 8 12 7 5 1 4 11 6109 32 8 12 7 5 1 4 11 6109 Real forest Equivalent forest merge(v,w): Case (a) v,w in different trees: link(v,w) Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin

46 Mergeable Trees46 Implicit Mergeable Trees 32 8 12 7 5 1 4 11 6 10 9 3 2 8 12 7 5 1 4 11 6 10 9 Real forest merge( 10, 11 ) merge(v,w): Case (a) v,w in different trees: link(v,w) Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin Equivalent forest

47 Mergeable Trees47 Implicit Mergeable Trees 32 8 12 7 5 1 4 11 6109 32 8 11 7 5 1 4 12 6 10 9 merge( 10, 11 ) Real forest merge(v,w): Case (a) v,w in different trees: link(v,w) Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin Equivalent forest

48 Mergeable Trees48 Implicit Mergeable Trees merge(v,w): Case (b) v,w in same tree: cut (u,q); link (v,w) where u = pathmin(v,w), q = successor of u in path from u to v 32 8 12 7 5 1 4 11 6109 32 8 11 7 5 1 4 12 6 10 9 Real forest Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin Equivalent forest

49 Mergeable Trees49 Implicit Mergeable Trees merge( 6, 12 ) 32 8 12 7 5 1 4 11 6 109 32 8 11 7 5 1 4 12 6 10 9 Real forest merge(v,w): Case (b) v,w in same tree: cut (u,q); link (v,w) where u = pathmin(v,w), q = successor of u in path from u to v Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin Equivalent forest

50 Mergeable Trees50 Implicit Mergeable Trees 32 8 12 7 5 1 4 11 6109 32 8 11 7 5 1 4 12 6 10 9 Real forest merge( 6, 12 ) merge(v,w): Case (b) v,w in same tree: cut (u,q); link (v,w) where u = pathmin(v,w), q = successor of u in path from u to v Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin Equivalent forest

51 Mergeable Trees51 Main idea: partition the vertices in a tree into disjoint solid paths connected by dashed edges, represent solid paths by search trees. Sleator and Tarjan’s Link-Cut Trees

52 Mergeable Trees52 Sleator and Tarjan’s Link-Cut Trees Main idea: partition the vertices in a tree into disjoint solid paths connected by dashed edges, represent solid paths by search trees.

53 Mergeable Trees53 Mergeable Trees via Partition by Rank 24(4) 16(4) 7(2) 6(2) 4(2) 1(0) 2(1) 3(1)4(2) 5(2) 6(2) 7(2) 5(2) 6(2)2(1) We can do better when arbitrary cuts are disallowed. (x,y) is solid if rank(x)=rank(y); dashed otherwise.

54 Mergeable Trees54 In every leaf to root path there are at most logn dashed arcs  nca(·,·) can be implemented in O(logn)-time worst case. We can do better when arbitrary cuts are disallowed. (x,y) is solid if rank(x)=rank(y); dashed otherwise. Mergeable Trees via Partition by Rank 24(4) 16(4) 7(2) 6(2) 4(2) 1(0) 2(1) 3(1)4(2) 5(2) 6(2) 7(2) 5(2) 6(2)2(1) Each node points to (a node that points to) The top node on its path.

55 Mergeable Trees55 Mergeable Trees via Partition by Rank We can do better when arbitrary cuts are disallowed. (x,y) is solid if rank(x)=rank(y); dashed otherwise. Merging idea: Insert nodes of lower rank into solid paths of higher rank. rank(p) ≥ rank(q) p q The rank of q increases by at least 1  O( n log n ) such insertions.

56 Mergeable Trees56 Mergeable Trees via Partition by Rank We can do better when arbitrary cuts are disallowed. (x,y) is solid if rank(x)=rank(y); dashed otherwise. Merging idea: Insert nodes of lower rank into solid paths of higher rank. rank(p) ≥ rank(q) q The rank of q increases by at least 1  O( n log n ) such insertions. p A prefix of the resulting path may change rank  O( n log n ) such events.

57 Mergeable Trees57 Mergeable Trees via Partition by Rank Operations: ( 1 ) insert a node in an arbitrary position on a solid path; ( 2 ) remove top node of a solid path. Solid paths represented by finger search trees. x z y P x = most-recently-accessed node of P z is inserted immediately below y cost ~ log(d+ 2 ) d = length of path from y to x d

58 Mergeable Trees58 Mergeable Trees via Partition by Rank x z y x = most-recently-accessed node of P z is inserted immediately below y cost ~ log(d+ 2 ) d = length of path from y to x d P d i = length of the (solid) insertion path for the i-th insertion ( 1 ≤i≤nlogn). Claim:

59 Mergeable Trees59 Open Problems  Get an O(logn)-time algorithm when arbitrary cuts are allowed.  Conjecture: The interleaved merging algorithm implemented with self-adjusting dynamic trees takes O(logn) amortized time per operation.  Other applications?


Download ppt "Mergeable Trees1 Mergeable Trees Mergeable Trees Robert E. Tarjan Princeton University and HP Labs Joint work with Loukas Georgiadis, Haim Kaplan, Nira."

Similar presentations


Ads by Google