1 / 78

A Tale Of Two Simple Data Structures

A Tale Of Two Simple Data Structures. Free, We Lunch.

donnan
Download Presentation

A Tale Of Two Simple Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Tale Of Two Simple Data Structures Free, We Lunch

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

  3. Fat Heaps • Meldable Heaps and Boolean Union-FindKaplan, Shafrir, TarjanSTOC 2002 • New Heap Data StructuresKaplan, Tarjan1998

  4. 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]

  5. Meldable Heap Interface

  6. Parallel Algorithms time

  7. Redundant Counters • We want to be able to add 1 to an arbitrary digit of a number in worst-case O(1) time.

  8. 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}.

  9. Pop Quiz • Who cannot tell me what 1001 is? • How about 201?

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

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

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

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

  14. 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*

  15. Add 1 in O(1) Time If the counter is 2-exposed, fix. Add 1 as usual.

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

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

  18. Pointer Diagram . . . d2 d1 d0

  19. Case 1 of 40 211021110 211022110+1 211102110fix 211110110fix 211110110 reform blocks

  20. Case 2 of 40 211021110 211021210+1 211101210fix 211102010fix 211102010 reform blocks

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

  22. 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]

  23. Back to Fat Heaps

  24. Heap Order 5 11 8 42 16 7 9

  25. Violations 5 11 8 42 3 7 9

  26. Fat Trees F0 is a single node Fk is threeFk-1 linked together: Fk-1 Fk-1 Fk-1

  27. Truly Fat Trees F2 F1 F0

  28. Nodes 4 pointers 1 word 5 r 12 7 r-1 r-1

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

  30. Root Counter

  31. Violation Counter

  32. MakeHeap() Initialize the two counters to 0 FindMin() Return the minimum pointer

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

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

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

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

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

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

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

  40. Questions?

  41. Dynamic Connectivity • Poly-Logarithmic Deterministic Fully-Dynamic Algorithms for Connectivity, MST, 2-Edge and BiconnectivityHolm, de Lichtenberg, ThorupJACM 2001

  42. Dynamic Connectivity Given a fixed set of n vertices

  43. Dynamic Connectivity Insert an edge

  44. Dynamic Connectivity Insert an edge

  45. Dynamic Connectivity Delete an edge

  46. Dynamic Connectivity Are u and v connected right now? u v

  47. 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]

  48. Jump To The • Reduction: dynamic maintenance a spanning forest

  49. Edge Insertion If the edge creates a cycle, no change is needed

More Related