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

Slides:



Advertisements
Similar presentations
Planar point location -- example
Advertisements

Dynamic Graph Algorithms - I
Priority Queues  MakeQueuecreate new empty queue  Insert(Q,k,p)insert key k with priority p  Delete(Q,k)delete key k (given a pointer)  DeleteMin(Q)delete.
1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
Rank-Pairing Heaps Robert Tarjan, Princeton University & HP Labs Joint work with Bernhard Haeupler and Siddhartha Sen, ESA
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
1 Self-Adjusting Data Structures. 2 Lists [D.D. Sleator, R.E. Tarjan, Amortized Efficiency of List Update Rules, Proc. 16 th Annual ACM Symposium on Theory.
A Randomized Linear-Time Algorithm to Find Minimum Spanning Trees David R. Karger David R. Karger Philip N. Klein Philip N. Klein Robert E. Tarjan.
Discussion #36 Spanning Trees
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
1 Dynamic graph connectivity Holm, Lichtenberg, Thorup (98) (based on Henzinger & King (95))
1 Finding Dominators in Flowgraphs Linear-Time Algorithm 1 and Experimental Study 2 Loukas Georgiadis 1 joint work with Robert E. Tarjan 2 joint work with.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Rank-Pairing Heaps Bernhard Haeupler, Siddhartha Sen, and Robert Tarjan, ESA
Dynamic Sets and Data Structures Over the course of an algorithm’s execution, an algorithm may maintain a dynamic set of objects The algorithm will perform.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
CSE 373, Copyright S. Tanimoto, 2002 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
5.9 Heaps of optimal complexity
Binary search trees Definition Binary search trees and dynamic set operations Balanced binary search trees –Tree rotations –Red-black trees Move to front.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 11 Tuesday, 12/4/01 Advanced Data Structures Chapters.
CS2420: Lecture 42 Vladimir Kulyukin Computer Science Department Utah State University.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
1 Binomial heaps, Fibonacci heaps, and applications.
IS 2610: Data Structures Graph April 5, 2004.
Algorithms 2005 Ramesh Hariharan. Amortization in Dynamic Algorithms A single insertion/deletion might take say O(log n) time Does a sequence of n insertions.
Multiple-Source Shortest Paths in Planar Graphs Allowing Negative Lengths Philip Klein Brown University.
New Balanced Search Trees Siddhartha Sen Princeton University Joint work with Bernhard Haeupler and Robert E. Tarjan.
CSCE350 Algorithms and Data Structure Lecture 17 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
Spring 2015 Lecture 11: Minimum Spanning Trees
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Computer Algorithms Submitted by: Rishi Jethwa Suvarna Angal.
Data Structures Haim Kaplan & Uri Zwick December 2013 Binary Heaps 1.
Path Minima on Dynamic Weighted Trees Pooya Davoodi Aarhus University Aarhus University, November 17, 2010 Joint work with Gerth Stølting Brodal and S.
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
WEEK 3 Leftist Heaps CE222 Dr. Senem Kumova Metin CE222_Dr. Senem Kumova Metin.
Preview  Graph  Tree Binary Tree Binary Search Tree Binary Search Tree Property Binary Search Tree functions  In-order walk  Pre-order walk  Post-order.
Union-find Algorithm Presented by Michael Cassarino.
Minimal Spanning Tree Problems in What is a minimal spanning tree An MST is a tree (set of edges) that connects all nodes in a graph, using.
Union Find ADT Data type for disjoint sets: makeSet(x): Given an element x create a singleton set that contains only this element. Return a locator/handle.
Union-Find A data structure for maintaining a collection of disjoint sets Course: Data Structures Lecturers: Haim Kaplan and Uri Zwick January 2014.
Université de Nantes Dynamic Trees and Log-lists Irena Rusu Université de Nantes, LINA
1 Fat heaps (K & Tarjan 96). 2 Goal Want to achieve the performance of Fibonnaci heaps but on the worst case. Why ? Theoretical curiosity and some applications.
Introduction Terrain Level set and Contour tree Problem Maintaining the contour tree of a terrain under the following operation: ChangeHeight(v, r) : Change.
Binary Search Trees.  Understand tree terminology  Understand and implement tree traversals  Define the binary search tree property  Implement binary.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
More Trees. Outline Tree B-Tree 2-3 Tree Tree Red-Black Tree.
CSE 373, Copyright S. Tanimoto, 2001 Up-trees - 1 Up-Trees Review of the UNION-FIND ADT Straight implementation with Up-Trees Path compression Worst-case.
CSE 373: Data Structures and Algorithms
Self-Adjusting Data Structures
Binary search trees Definition
Data Structures: Disjoint Sets, Segment Trees, Fenwick Trees
Chapter 5 : Trees.
Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick
Binomial heaps, Fibonacci heaps, and applications
Heaps Binomial Heaps Lazy Binomial Heaps 1.
CS 3343: Analysis of Algorithms
Data Structures Lecture 4 AVL and WAVL Trees Haim Kaplan and Uri Zwick
Selection in heaps and row-sorted matrices
A simpler implementation and analysis of Chazelle’s
Strict Fibonacci Heaps
CSE373: Data Structures & Algorithms Implementing Union-Find
June 12, 2003 (joint work with Umut Acar, and Guy Blelloch)
Binomial heaps, Fibonacci heaps, and applications
Important Problem Types and Fundamental Data Structures
CSE 373: Data Structures and Algorithms
Dynamic graph connectivity
Presentation transcript:

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

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

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

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.

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.

Mergeable Trees6 Example

Mergeable Trees7 Example merge( 5, 2 )

Mergeable Trees8 Example merge( 6, 11 )

Mergeable Trees9 Example merge( 6, 11 ) merge( 7, 8 )

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.

Mergeable Trees11 Turbo Exhaust Manifold

Mergeable Trees 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

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

Mergeable Trees Reeb GraphMergeable Trees Example

Mergeable Trees Reeb GraphMergeable Trees 1 2 (3) 3 (2) pair(3,2) merge(3,1) merge(3,2) Example

Mergeable Trees Reeb GraphMergeable Trees 1 2 (3) 3 (2) merge(4,3) merge(5,4) merge(6,4) Example

Mergeable Trees Reeb GraphMergeable Trees 1 2 (3) 3 (2) (7) 7 (5) 10 pair(7,5) merge(7,5) Example

Mergeable Trees 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

Mergeable Trees 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

Mergeable Trees 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

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

Mergeable Trees Reverse Reeb GraphMergeable Trees (1) 1 (10) 10 (max) is paired with 1 (min) Reverse Pass of Two-Pass Algorithm

Mergeable Trees Reverse Reeb GraphMergeable Trees (1) merge(8,9) merge(7,8) 1 (10) Reverse Pass of Two-Pass Algorithm

Mergeable Trees Reverse Reeb GraphMergeable Trees (9) 8 9 (6) (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

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

Mergeable Trees Reverse Reeb GraphMergeable Trees (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

Mergeable Trees Reverse Reeb GraphMergeable Trees 1 (10) (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

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

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)

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.

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

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.

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).

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).

Mergeable Trees35 Mergeable Trees via Dynamic Trees

Mergeable Trees36 Mergeable Trees via Dynamic Trees

Mergeable Trees37 Mergeable Trees via Dynamic Trees

Mergeable Trees38 Mergeable Trees via Dynamic Trees

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)

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)

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).

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.

Mergeable Trees43 Implicit Mergeable Trees Parents are computable but not efficiently. Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin

Mergeable Trees44 Implicit Mergeable Trees 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

Mergeable Trees45 Implicit Mergeable Trees 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

Mergeable Trees46 Implicit Mergeable Trees 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

Mergeable Trees47 Implicit Mergeable Trees 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

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 Real forest Each mergeable tree represented by an equivalent unrooted dynamic tree: root = treemin, nca = pathmin Equivalent forest

Mergeable Trees49 Implicit Mergeable Trees merge( 6, 12 ) 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

Mergeable Trees50 Implicit Mergeable Trees 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

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

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.

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.

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.

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.

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.

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

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:

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?