230 likes | 360 Views
STACS 2006. Amortized Rigidness in Dynamic Cartesian Trees. Iwona Białynicka-Birula and Roberto Grossi Universit à di Pisa. 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
E N D
STACS 2006 Amortized Rigidness inDynamic Cartesian Trees Iwona Białynicka-Birula and Roberto GrossiUniversità di Pisa
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 • xvalue partitions remaining points(left and right subtrees) 23rd International Symposium on Theoretical Aspects of Computer Science
Cartesian tree example 〈2, 22〉 〈19, 21〉 〈21, 20〉 〈18, 19〉 〈4, 18〉 〈6, 17〉 〈20, 16〉 〈7, 15〉 〈8, 13〉 〈5, 12〉 〈9, 11〉 〈17, 10〉 〈3, 9〉 〈16, 8〉 〈10, 7〉 〈22, 6〉 〈14, 5〉 〈15, 4〉 〈12, 3〉 〈1, 2〉 〈11, 1〉 23rd International Symposium on Theoretical Aspects of Computer Science
Applications • Priority queue • Randomized searching (treaps) • Range and dominance searching • RMQ (Range Maximum Query) • LCA (Least Common Ancestor) • Integer sorting • Memory management • Suffix trees • ... 23rd International Symposium on Theoretical Aspects of Computer Science
From RMQ to LCA 22 21 20 19 18 18 17 17 16 15 15 13 13 12 12 11 11 10 9 9 8 7 7 6 5 4 3 2 1 1 2, 22, 9, 18, 12, 17, 15, 13, 11, 7, 1, 3, 5, 4, 8, 10, 19, 21, 16, 20, 6 9, 18, 12, 17, 15, 13, 11, 7, 1 23rd International Symposium on Theoretical Aspects of Computer Science
I M... P $ S 12 1 I$ PI$ I SI $ P... SSI P... S... 10 9 11 8 7 4 P... S... P... S... 6 3 5 2 From LCP array to suffix tree 12 11 8 5 2 1 10 9 7 4 6 3 $ I$ IPPI$ ISSIPPI$ ISSISSIPPI$ MISSISSIPPI$ PI$ PPI$ SIPPI$ SISSIPPI$ SSIPPI$ SSISSIPPI$ 0 1 1 4 0 0 1 0 2 1 3 0 1 1 4 0 0 1 0 2 1 3 23rd International Symposium on Theoretical Aspects of Computer Science
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 • ??? 23rd International Symposium on Theoretical Aspects of Computer Science
Our result • Dynamic Cartesian tree • Supports insertion • Supports weak deletion • Maintains actual tree structure between each operation • O(log n) amortized time per operation 23rd International Symposium on Theoretical Aspects of Computer Science
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 23rd International Symposium on Theoretical Aspects of Computer Science
Insertion 〈2, 22〉 〈19, 21〉 〈21, 20〉 〈18, 19〉 〈4, 18〉 〈6, 17〉 〈20, 16〉 〈7, 15〉 〈13, 14〉 〈8, 13〉 〈5, 12〉 〈9, 11〉 〈17, 10〉 〈3, 9〉 〈16, 8〉 〈10, 7〉 〈22, 6〉 〈14, 5〉 〈15, 4〉 〈12, 3〉 〈1, 2〉 〈11, 1〉 23rd International Symposium on Theoretical Aspects of Computer Science
Insertion – worst case 〈9, 17〉 〈1, 16〉 〈17, 15〉 〈2, 14〉 〈16, 13〉 〈3, 12〉 〈15, 11〉 〈4, 10〉 〈14, 9〉 〈5, 8〉 〈13, 7〉 〈6, 6〉 〈12, 5〉 〈7, 4〉 〈11, 3〉 〈8, 2〉 〈10, 1〉 23rd International Symposium on Theoretical Aspects of Computer Science
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 23rd International Symposium on Theoretical Aspects of Computer Science
Insertion revisited > > > > > > > > > > > 23rd International Symposium on Theoretical Aspects of Computer Science
Insertion reversed (deletion) ? ?? ? ? 23rd International Symposium on Theoretical Aspects of Computer Science
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 Formally... C > > B E > > > A D I > > J G > > F H A B H J F G I D E C H A J F G I D B E C A J D F H G I B E C D J I A H F G E B C H J D A F G I E B C A D H F G J I B E C . . . 23rd International Symposium on Theoretical Aspects of Computer Science
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) 23rd International Symposium on Theoretical Aspects of Computer Science
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 23rd International Symposium on Theoretical Aspects of Computer Science
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 23rd International Symposium on Theoretical Aspects of Computer Science
Insertion once again • 1. Find parent • 2. Edges affected • 3a. Delete 2 • 3b. Insert 3 • 4. Shrink k 3b. Insert 3 1. Find parent 2. Edges affected 3a. Delete 2 4. Shrink k 23rd International Symposium on Theoretical Aspects of Computer Science
Action implementations • Find parent • Uses the interval tree as a search tree • Edges affected • Special kind of stabbing query • Insert and delete • Standard interval tree operations • 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) 23rd International Symposium on Theoretical Aspects of Computer Science
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 23rd International Symposium on Theoretical Aspects of Computer Science
Further work • Strong deletion • Applications • For example RMQ 23rd International Symposium on Theoretical Aspects of Computer Science
Thank you! • Questions? 23rd International Symposium on Theoretical Aspects of Computer Science