Dynamic Trees - PowerPoint PPT Presentation

About This Presentation
Title:

Dynamic Trees

Description:

Reverse Reeb Graph. Mergeable Trees. 2. 3. 4. 6 (9) 8. 9 (6) 5 (7) 7 (5) ... Reverse Pass of Two-Pass Algorithm. Mergeable Trees. 28. Mergeable Trees: Results ... – PowerPoint PPT presentation

Number of Views:221
Avg rating:3.0/5.0
Slides: 60
Provided by: rfw4
Category:
Tags: dynamic | reverse | trees

less

Transcript and Presenter's Notes

Title: Dynamic Trees


1
Mergeable TreesRobert E. TarjanPrinceton
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
Outline
  • The Problem
  • The Motivating Application
  • Dynamic Trees
  • Mergeable Trees via Dynamic Trees
  • Implicit Mergeable Trees
  • Mergeable Trees via Partition by Rank
  • Open Problems

3
Mergeable Trees
  • Goal Maintain a forest of rooted trees.
  • Queries

parent(v)
root(v)
nca(v,w)
4
Mergeable Trees
  • Goal Maintain a forest of rooted trees.
  • Queries

parent(v)
root(v)
nca(v,w)
  • Trees are heap-ordered (rootsmallest)
  • Updates

insert(v)
merge(v,w) merge the v-to-root and w-to-root
paths, preserving the heap
order.
5
Mergeable Trees
  • Goal Maintain a forest of rooted trees.
  • Queries

parent(v)
root(v)
nca(v,w)
  • Trees are heap-ordered (rootsmallest)
  • 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
Example
1
3
2
6
7
4
9
8
5
10
11
7
Example
1
1
3
2
3
2
merge(5,2)
6
7
4
6
7
4
5
9
8
9
8
10
11
5
10
11
8
Example
1
3
2
merge(6,11)
1
6
7
4
5
2
9
8
10
11
4
3
7
5
9
8
6
10
11
9
Example
1
3
2
merge(6,11)
1
6
7
4
5
2
9
8
10
11
4
3
7
5
1
9
8
6
merge(7,8)
2
10
11
3
5
4
6
7
9
10
8
11
10
Mergeable Trees Motivation
  • Used in Agarwal, Edelsbrunner, Harer and Wang
    04
  • sub-problem in their algorithm for computing the
    structure of 2-manifolds embedded in R3.
  • 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
Turbo Exhaust Manifold
12
Reeb Graph encodes skeleton of manifold
10
Nodes in Reeb Graph
9
8
sink (0 out-degree)
7
6
source (0 in-degree)
5
4
up-fork (1 in, 2 out)
3
down-fork (2 in, 1 out)
2
1
13
Pairing Algorithm on Reeb Graph
x
merge(x,v)
v
root(v) ? root(w) pair x with maxroot(v),root(w)

x
root(v) root(w) pair x with nca(v, w)
v
w
merge(x,v) merge(x,w)
merge(x,v)
x
sink
while v is paired, replace by parent(v)
v
pair x with v
14
Example
10
10
9
9
8
8
7
7
6
6
5
5
4
4
3
3
2
2
1
1
Reeb Graph
Mergeable Trees
15
Example
10
10
9
9
8
8
7
7
6
6
5
5
4
pair(3,2) merge(3,1) merge(3,2)
4
3
3 (2)
2
2 (3)
1
1
Reeb Graph
Mergeable Trees
16
Example
10
10
9
9
8
8
7
7
6
6
5
5
4
merge(4,3) merge(5,4) merge(6,4)
4
3
3 (2)
2
2 (3)
1
1
Reeb Graph
Mergeable Trees
17
Example
10
10
9
9
8
8
7
7 (5)
6
6
5
5 (7)
4
pair(7,5) merge(7,5)
4
3
3 (2)
2
2 (3)
1
1
Reeb Graph
Mergeable Trees
18
Example
10
10
9
9
8
8 (4)
7
7 (5)
6
6
5
5 (7)
4
4 (8)
pair(8,4) merge(8,7) merge(8,6)
3
3 (2)
2
2 (3)
1
1
Reeb Graph
Mergeable Trees
19
Example
10
10
9
9 (6)
8
8 (4)
7
7 (5)
6
6 (9)
5
5 (7)
4
4 (8)
merge(9,8) pair(9,6) (6 is the closest unpaired
ancestor of 9)
3
3 (2)
2
2 (3)
1
1
Reeb Graph
Mergeable Trees
20
Example
10
10
9
9 (6)
8
8 (4)
7
7 (5)
6
6 (9)
5
5 (7)
4
4 (8)
merge(10,6) pair(10,1) (1 is the closest unpaired
ancestor of 10)
3
3 (2)
2
2 (3)
1
Reeb Graph
Mergeable Trees
21
Two-Pass Algorithm
To avoid parent operation Pair max with
min Run algorithm forward and backward Do no
pairing in sink case
22
Reverse Pass of Two-Pass Algorithm
10
10 (1)
9
9
8
8
7
7
6
6
5
5
10 (max) is paired with 1 (min)
4
4
3
3
2
2
1 (10)
1
Reverse Reeb Graph
Mergeable Trees
23
Reverse Pass of Two-Pass Algorithm
10
10 (1)
9
9
8
8
7
7
6
6
5
5
merge(8,9) merge(7,8)
4
4
3
3
2
2
1 (10)
1
Reverse Reeb Graph
Mergeable Trees
24
Reverse Pass of Two-Pass Algorithm
10
10 (1)
9
9 (6)
8
8
7
7
6
6 (9)
pair(9,6) merge(6,8) merge(6,10) pair 6 with
root of min label this pair is missing from
forward pass.
5
5
4
4
3
3
2
2
1 (10)
1
Reverse Reeb Graph
Mergeable Trees
25
Reverse Pass of Two-Pass Algorithm
10
10 (1)
9
9 (6)
8
8
7
7 (5)
6
6 (9)
5
5 (7)
pair(5,7) merge(5,7)
4
4
3
3
2
2
1 (10)
1
Reverse Reeb Graph
Mergeable Trees
26
Reverse Pass of Two-Pass Algorithm
10
10 (1)
9
9 (6)
8
8 (4)
7
7 (5)
6
6 (9)
5
5 (7)
pair(4,8) merge(4,5) merge(4,6)
4
4 (8)
3
3
2
2
1 (10)
1
Reverse Reeb Graph
Mergeable Trees
27
Reverse Pass of Two-Pass Algorithm
10
10 (1)
9
9 (6)
8
8 (4)
7
7 (5)
6
6 (9)
5
5 (7)
merge(3,4) merge(1,3) merge(2,3)
4
4 (8)
3
3
2
2
1 (10)
1
Reverse Reeb Graph
Mergeable Trees
28
Mergeable Trees Results
n number of nodes in merges m number of
merges O(log2n) amortized time per
operation O(logn) amortized time without
cuts O(logn) worst-case without cuts, parent
queries
29
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
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 Trees via Dynamic Trees
  • 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.

a
b
c
d
f
e
g
i
h
j
l
m
k
q
p
r
s
o
n
t
u
v
w
32
Mergeable Trees via Dynamic Trees
  • 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.

a
b
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
c
d
f
e
g
i
h
j
l
m
k
q
p
r
s
o
n
t
u
v
w
33
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.
a
  • Better idea Interleaved Merges
  • Cut edges where parents change and link the
    pieces together.
  • Time is O(cuts logn).

b
c
d
f
e
g
i
h
j
l
m
k
q
p
r
s
o
n
t
u
v
w
34
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.
a
  • Better idea Interleaved Merges
  • Cut edges where parents change and link the
    pieces together.
  • Time is O(cuts logn).

b
c
d
f
e
g
i
h
j
l
m
k
To enable fast merging Query topmost(v,w)
return the smallest (topmost) ancestor of v
strictly greater than w. (assume vgtw)
q
p
r
s
r
o
n
t
u
v
w
35
Mergeable Trees via Dynamic Trees
1
2
4
1
3
5
2
3
10
6
11
7
12
8
9
13
14
36
Mergeable Trees via Dynamic Trees
1
2
4
1
3
5
2
4
3
10
5
6
11
7
12
8
9
13
14
37
Mergeable Trees via Dynamic Trees
1
2
4
1
3
5
2
4
3
10
5
6
11
6
7
12
7
8
8
9
9
13
14
38
Mergeable Trees via Dynamic Trees
1
2
4
1
3
5
2
4
3
10
5
6
11
6
7
12
7
8
8
9
9
13
10
14
11
12
13
14
39
Analysis of Merge
parent changes O(m logn).
w
log(v-w)
1
v
log(v-w)
Each node has parent potential (on its parent)
has child potential (on its
children).
40
Analysis of Merge
parent changes O(m logn).
w
log(v-w)
1
v
log(v-w)
cut (or delete) one parent change (to null) ?
F ? 1.
41
Analysis of Merge
parent changes O(m logn).
w
log(v-w)
1
v
log(v-w)
cut (or delete) one parent change (to null) ?
F ? 1.
merge(v,w) F ? O(logn) if v,w in different
trees (initial link).
42
Analysis of Merge
parent changes O(m logn).
w
log(v-w)
1
v
log(v-w)
z
z
y
All other F changes are non-positive.
?
w
x
w-x (w-z)/2 ? parent potential of w ? 1 y-z
(w-z)/2 ? child potent of z ? 1
w
Pays for parent change of w.
43
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
Parents are computable but not efficiently.
1
4
3
2
5
7
8
6
10
9
12
11
44
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
  • merge(v,w) Case (a) v,w in different trees
    link(v,w)

1
4
3
2
5
7
8
6
10
9
12
11
45
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
merge(v,w) Case (a) v,w in different trees
link(v,w)
1
1
4
4
3
2
5
3
2
5
7
7
8
8
6
10
9
6
10
9
12
11
12
11
Real forest
Equivalent forest
46
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
merge(v,w) Case (a) v,w in different trees
link(v,w)
merge(10,11)
1
1
4
4
3
2
5
3
2
5
7
7
8
8
6
10
9
6
10
9
12
11
12
11
Real forest
Equivalent forest
47
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
merge(v,w) Case (a) v,w in different trees
link(v,w)
merge(10,11)
1
3
2
1
4
3
2
5
4
7
5
7
8
6
10
9
8
6
9
12
11
12
10
11
Real forest
Equivalent forest
48
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
  • 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
1
3
2
1
4
3
2
5
4
7
5
7
8
6
10
9
8
6
9
12
11
12
10
11
Real forest
Equivalent forest
49
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
  • 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
merge(6,12)
1
3
2
1
4
3
2
5
4
7
5
7
8
6
10
9
8
6
9
12
11
12
10
11
Real forest
Equivalent forest
50
Implicit Mergeable Trees
Each mergeable tree represented by an equivalent
unrooted dynamic tree root treemin, nca
pathmin
  • 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
merge(6,12)
1
3
2
1
4
4
5
3
2
5
7
6
8
6
10
9
7
12
11
8
9
12
10
11
Real forest
Equivalent forest
51
Sleator and Tarjans 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.

52
Sleator and Tarjans 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 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.
24(4)
16(4)
7(2)
7(2)
6(2)
6(2)
2(1)
6(2)
1(0)
5(2)
5(2)
4(2)
1(0)
3(1)
4(2)
1(0)
1(0)
1(0)
2(1)
2(1)
1(0)
1(0)
1(0)
1(0)
54
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.
24(4)
16(4)
7(2)
  • In every leaf to root path there are
  • at most logn dashed arcs
  • nca(,) can be implemented
  • in O(logn)-time worst case.

7(2)
6(2)
6(2)
2(1)
6(2)
1(0)
5(2)
5(2)
4(2)
1(0)
3(1)
4(2)
1(0)
Each node points to (a node that points to) The
top node on its path.
1(0)
1(0)
2(1)
2(1)
1(0)
1(0)
1(0)
1(0)
55
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.
p
The rank of q increases by at least 1 ? O(nlogn)
such insertions.
q
rank(p) rank(q)
56
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.
The rank of q increases by at least 1 ? O(nlogn)
such insertions.
p
q
  • A prefix of the resulting path may change rank
  • O(nlogn) such events.

rank(p) rank(q)
57
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
x most-recently-accessed node of P z is
inserted immediately below y cost log(d2) d
length of path from y to x
d
z
y
P
58
Mergeable Trees via Partition by Rank
di length of the (solid) insertion path for the
i-th insertion (1inlogn). Claim
x
x most-recently-accessed node of P z is
inserted immediately below y cost log(d2) d
length of path from y to x
d
z
y
P
59
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?
Write a Comment
User Comments (0)
About PowerShow.com