23
Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

  • View
    215

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

Amortized Rigidness in Dynamic Cartesian TreesIwona Białynicka-Birula and Roberto GrossiUniversità di Pisa

STACS 2006

Page 2: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 2

Cartesian trees Vuillemin 1980 Nodes store points ⟨x, y⟩

y value can be viewed as priority Recursive definition

Root stores point with greatest y value x value partitions remaining points(left and right subtrees)

Page 3: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 3

Cartesian tree example ⟨2, 22⟩ ⟨21, 20⟩⟨18, 19⟩⟨6, 17⟩ ⟨20, 16⟩⟨7, 15⟩⟨8, 13⟩⟨5, 12⟩ ⟨9, 11⟩ ⟨17, 10⟩⟨3, 9⟩ ⟨16, 8⟩⟨10, 7⟩ ⟨22, 6⟩⟨15, 4⟩⟨12, 3⟩⟨1, 2⟩ ⟨11, 1⟩

⟨19, 21⟩⟨4, 18⟩

⟨14, 5⟩

Page 4: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 4

Applications Priority queue Randomized searching (treaps) Range and dominance searching RMQ (Range Maximum Query) LCA (Least Common Ancestor) Integer sorting Memory management Suffix trees ...

Page 5: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 5

From RMQ to LCA

2, 22, 9, 18, 12, 17, 15, 13, 11, 7, 1, 3, 5, 4, 8, 10, 19, 21, 16, 20, 6

22 201917 16151312 11 109 87 6432 1

2118

59, 18, 12, 17, 15, 13, 11, 7, 1

17151312 119 71

18

Page 6: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 6

From LCP array to suffix tree$I$IPPI$ISSIPPI$ISSISSIPPI$MISSISSIPPI$PI$PPI$SIPPI$SISSIPPI$SSIPPI$SSISSIPPI$

0 1 1 4 0 0 1 0 2 1 3$ I M... P S

$ P... SSI

P... S...

I$ PI$ I SI

P... S...

P... S...

1

23

4

56

78 91011

12

121185211097463

01140010213

Page 7: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 7

History Static setting

O(n) construction time, provided elements already sorted Randomized

Random priority values – treaps O(log n) expected height O(log n) expected update time

Other distributions yield O(√n) or even O(n) height (Devroye 1994) Dynamic and deterministic

???

Page 8: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 8

Our result Dynamic Cartesian tree

Supports insertion Supports weak deletion Maintains actual tree structure between each operation O(log n) amortized time per operation

Page 9: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 9

Solution outline Combinatorial analysis

How many tree elements change due to n insertions? Notion of entropy is exploited

Auxiliary structure for accessing tree Needed to quickly access tree elements which need to change Based on the interval tree

Page 10: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 10

Insertion ⟨2, 22⟩ ⟨21, 20⟩⟨18, 19⟩⟨6, 17⟩ ⟨20, 16⟩⟨7, 15⟩⟨8, 13⟩⟨5, 12⟩ ⟨9, 11⟩ ⟨17, 10⟩⟨3, 9⟩ ⟨16, 8⟩⟨10, 7⟩ ⟨22, 6⟩⟨15, 4⟩⟨12, 3⟩⟨1, 2⟩ ⟨11, 1⟩

⟨19, 21⟩⟨4, 18⟩

⟨14, 5⟩

⟨13, 14⟩

Page 11: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 11

Insertion – worst case⟨1, 16⟩

⟨7, 4⟩⟨8, 2⟩

⟨17, 15⟩⟨16, 13⟩⟨15, 11⟩⟨14, 9⟩⟨13, 7⟩⟨12, 5⟩⟨11, 3⟩⟨10, 1⟩

⟨2, 14⟩⟨3, 12⟩⟨4, 10⟩⟨5, 8⟩⟨6, 6⟩

⟨9, 17⟩

Page 12: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 12

Analysis – main idea Inserting new elements does not require comparing y coordinates of existing points In turn, deleting points does Conclusion: insertions reduce tree information content ... so information entropy can be used as a potential function in an amortized analysis

Page 13: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 13

>> >

>>>

>

>>

>>

Insertion revisited

Page 14: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 14

Insertion reversed (deletion)

?????

Page 15: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 15

Formally... Tree T induces partial order ≺T on nodes

Defined by the heap condition Partial order ≺T has ℒ(T) linear extensions

Linear extensions are permutations satisfying the order, i.e. P[i] ≺T P[j] ⇒ i < j We define missing entropy: ℋ(T)=log ℒ(T)

Information needed to sort nodes given tree topology

> > >>> >>>>A B CD E IG JF H

A B H J F G I D E CH A J F G I D B E CA J D F H G I B E CD J I A H F G E B CH J D A F G I E B CA D H F G J I B E C. . .

Page 16: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 16

Missing entropy Can be zero ℋ(T)=0 Or can be up to ℋ(T)=O(n log n) When an insertion affects k edges, ℋ(T) increases by at least Ω(k)

Page 17: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 17

So what now? Amortized number of edge modifications is O(log n) per insertion into an initially empty tree

Node modifications are always constant But how to access the edges to modify?

Without increasing the complexity

Page 18: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 18

Implementation overview Companion interval tree stores tree edges Edges in Cartesian tree are either disjoint or nested

So the interval tree has additional properties Operations are tailored to the special case of the Cartesian tree

Page 19: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 19

Insertion once again

1. Find parent2. Edges affected

4. Shrink k3a. Delete 2

3b. Insert 31. Find parent2. Edges affected3a. Delete 23b. Insert 34. Shrink k

Page 20: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 20

Action implementations1. Find parent

Uses the interval tree as a search tree2. Edges affected Special kind of stabbing query3. Insert and delete Standard interval tree operations4. Shrink Emulating using inserts and deletes would yield O(k∗log n) Amortized argument based on the fact that shrinking edge travels down

O(log n)O(log n+k)

O(1)∗O(log n)k∗O(1)

Page 21: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 21

Summary Scheme for maintaining a Cartesian tree under insertion and week deletion

Amortized O(log n) time per update At any moment the actual tree structure is accessible

Solution components Combinatorial analysis of tree behavior Auxiliary data structure

First result on dynamic Cartesian trees in a non-stochastic setting

Page 22: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 22

Further work

Strong deletion Applications

For example RMQ

Page 23: Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006

23 February 2006 23rd International Symposium on Theoretical Aspects of Computer Science 23

Thank you!

Questions?