780 likes | 881 Views
A Tale Of Two Simple Data Structures. Free, We Lunch.
E N D
A Tale Of Two Simple Data Structures Free, We Lunch
It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us, we were all going direct to Heaven, we were all going direct the other way . . .
Fat Heaps • Meldable Heaps and Boolean Union-FindKaplan, Shafrir, TarjanSTOC 2002 • New Heap Data StructuresKaplan, Tarjan1998
Binary [Williams 64] [Floyd 64] Binomial [Vuillemin 78] Leftist[Crane 72] Post Order[Harvey Zatloukal 04] V[Peterson 87] Fibonacci [Fredman Tarjan 87] Skew[Sleator Tarjan 86] [Brodal 95] Relaxed * 2[Driscoll+ 88] Relaxed Fibonacci[Boyapati+ 95] [Brodal Okasaki 95] Thin and Fat[Kaplan Tarjan 98] Pairing[Fredman+ 86] [Brodal 96] Soft[Chazelle 00] Fishspear[Fischer Paterson 94]
Parallel Algorithms time
Redundant Counters • We want to be able to add 1 to an arbitrary digit of a number in worst-case O(1) time.
2 {0, 1} Let’s Count Positional Number System of base b • dndn-1...d1d0 denotes Usually the set of digits is {0,…, b-1}.
Pop Quiz • Who cannot tell me what 1001 is? • How about 201?
Redundant Counters We allow one more digit in “binary numbers”: 2 (201)2= 2*4 + 1= 9 (121)2= 1*4 + 2*2 + 1= 9
Regularity A counter is regular iff between every two 2’s there is a digit other than 1. Regularity does not entail unique representation. • 2002 • 2120 From here on,we operate onlyonregular counters. (2)2 (10)2
Exposure Let’s call 0 and 2 “special”. If the last special digit of a counter is d, then the counter is d-exposed. 2012 2-exposed 2011 0-exposed
0-exposed At worst turn into a2-exposed (regular) counter 2-exposed Can turn irregular +1 Observation 2011 2012 2021 2022 2020 2021 2012 2013 ??? 2010 2011
Fixing 2-exposure This is the time for carry. We fix the rightmost 2. x is 0-exposed x21* We know how to add 1 to a 0-exposed number (x+1)01*
Add 1 in O(1) Time If the counter is 2-exposed, fix. Add 1 as usual.
Arbitrary Position Use fix to match original exposure, delete block when needed • If originally the prefix is 2-exposed, done. • Otherwise (0-exposed), fix. Question is how to locate the rightmost 2 in the prefix… xdiy
Implementation Uses worst-case resizable array (doubling + copy on write) [Brodal 96] (easier to explain than [Kaplan Tarjan 98]): Mark blocks of digits with the form and leave the other digits unmarked. 21*0
Pointer Diagram . . . d2 d1 d0
Case 1 of 40 211021110 211022110+1 211102110fix 211110110fix 211110110 reform blocks
Case 2 of 40 211021110 211021210+1 211101210fix 211102010fix 211102010 reform blocks
Redundant Counters We can implement a counter in any base so thatan arbitrary digit can be incremented in O(1) time. The length of the counter is logarithmic in its value.
Structure of Amortization The 2-for-1 phenomena • Finger Search Tree [Guibas+ 77] • Implicit Binomial Queue [Carlsson+ 88] • Persistent List [Kaplan Tarjan 95] • Heaps [Brodal 95] [Brodal 96]
Heap Order 5 11 8 42 16 7 9
Violations 5 11 8 42 3 7 9
Fat Trees F0 is a single node Fk is threeFk-1 linked together: Fk-1 Fk-1 Fk-1
Truly Fat Trees F2 F1 F0
Nodes 4 pointers 1 word 5 r 12 7 r-1 r-1
Fat Heaps A fat heap is a forest of almost heap-ordered fat trees,with at most 3 Fk per k,and at most 2 heap-order violations per rank. Other Ingredients: • a minimum pointer to the minimum element • a redundant ternary root counter to control the trees • a redundant binary violation counter to control the violations
MakeHeap() Initialize the two counters to 0 FindMin() Return the minimum pointer
Insert(h, x) Make a F0 out of x Add to the root counter, perform fix by linking 3 Fk-1 Fk Fk-1 Fk-1 Fk-1 Fk-1 fix Fk-1 Fk-1
DecreaseKey(h, x, ) Reduce x by If x is now smaller than the minimum, swap. If x is now a violation, add 1 to the r-th digit of the violation counter where r is the rank of x. But how to fix two rank r violations into one rank (r+1)?
Fixing Violations – Step 1 Arrange the violations to have the same parent, assume a < b a b a b exchange v w c c w v r r r r r r r r
Fixing Violations – Step 2a If the parent is of rank r+1, assuming v < w: (x can be a new violation at its parent) b v r+1 r+1 re-link w v w b r r r r
Fixing Violations – Step 2b If the parent is of rank larger than r+1: b b r+5 r+5 re-link e w v v f g r+1 r r r+1 r r f g e w r r r r
DeleteMin(h) We have all the time in the world, WAH HA HA! • Fix all violations in O(log n) time Now similar to Binomial Heaps • Remove the minimum root, exposing its O(log n) children • Insert each child one by one into root counter • Scan for minimum among the roots
Meld(h1, h2) Assume h2 is not the larger heap • Fix all violations in h2 in O(log n) time • Insert trees in h2 one by one into h1 • Update the minimum pointer if necessary
Dynamic Connectivity • Poly-Logarithmic Deterministic Fully-Dynamic Algorithms for Connectivity, MST, 2-Edge and BiconnectivityHolm, de Lichtenberg, ThorupJACM 2001
Dynamic Connectivity Given a fixed set of n vertices
Dynamic Connectivity Insert an edge
Dynamic Connectivity Insert an edge
Dynamic Connectivity Delete an edge
Dynamic Connectivity Are u and v connected right now? u v
m1/2, O(1)[Frederickson 83] n1/2, O(1)[Eppstein+ 92] log3 n, log n / log log n[Henzinger King 95] log2 n, log n / log log n [Henzinger Thorup 96] n1/3 log n, O(1) [Henzinger King 97] log2 n, log n / log log n[Holm+ 98]
Jump To The • Reduction: dynamic maintenance a spanning forest
Edge Insertion If the edge creates a cycle, no change is needed