1 / 51

A balanced binary tree, with items in the leaves in left-right order by decreasing key slope. The tree is a tournament

Simple heap (details) . A balanced binary tree, with items in the leaves in left-right order by decreasing key slope. The tree is a tournament on items by current key. d. c. b. e. a. a. a. c. a. d. e. c. b. a. 3. 2. 5. 4. 1. 7. 6. Simple kinetic heaps (Cont).

meda
Download Presentation

A balanced binary tree, with items in the leaves in left-right order by decreasing key slope. The tree is a tournament

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. Simple heap (details) A balanced binary tree, with items in the leaves in left-right order by decreasing key slope. The tree is a tournament on items by current key.

  2. d c b e a a a c a d e c b a 3 2 5 4 1 7 6

  3. Simple kinetic heaps (Cont) Add swap times at internal nodes

  4. d c b e 4.4 a a 6 a c 6.8 3 a d e c b a 3 2 5 4 1 7 6

  5. Simple kinetic heaps (Cont) Add minimum future swap time

  6. d c b e 4.4 a 3 a 6 6.8 a c 3 6.8 3 3 a d e c b a 3 2 5 4 1 7 6

  7. Simple kinetic heaps (Cont) When we do a find-min if the current time moves forward, we act as follows: Locate all nodes whose winner changes. The paths from the root to those nodes form a subtree. Update this subtree

  8. d c b e 4.4 a 3 a 6 6.8 a c 3 6.8 3 3 a d e c b a 3 2 5 4 1 7 6

  9. d c b e 4.4 a 3 a 6 6.8 a c 3 6.8 3 3 a d e c b a 3 2 5 4 1 7 6

  10. d c b e 4.4 a 3 a 6 6.8 a c 3 6.8 3  b d e c b a 3 3 2 2 5 5 4 4 1 1 7 7 6 6

  11. d c b e 4.4 a 3 a 20 6.8 b c 20 6.8 3  b d e c b a 3 2 5 4 1 7 6

  12. d c b e 5 b 5 a 20 6.8 b c 20 6.8 3  b d e c b a 3 2 5 4 1 7 6

  13. d c b e 5 b 5 a 20 6.8 b c 20 6.8 3  b d e c b a 3 2 5 4 1 7 6

  14. d c b e 5 b 5 a 20 6.8 b c 20 6.8 3  b d e c b a 3 2 5 4 1 7 6

  15. d c b e 5 20 e a 20 6.8 b e 20  3  b d e c b a 3 2 5 4 1 7 6

  16. d c b e 6.3 20 e a 20 6.8 b e 20  3  b d e c b a 3 2 5 4 1 7 6

  17. Simple kinetic heaps – insert & delete Use the regular mechanism of (say) red-black trees

  18. f 3 2 5 4 1 7 6 d c b e 5 20 e a 20 6.8 b e 20  3  b d e c b a

  19. 3 2 5 4 1 7 6 d c b e 20 5 e a f 20 6.8 b e 20  3 -20  b  e f c f d b a

  20. 3 2 5 4 1 7 6 d c b e  6.9 e a f -10 6.8 f e   3 -20  b  e f c f d b a

  21. Simple kinetic heaps (analysis) Find-min takes O(1) time if we do not advance the current time. Advancing the current time can be expensive on the worst-case Amortization: Assign O(log n) potential to each node whose swap time is in the future. This potential pays for advancing the time. So find-min takes O(1) amortized time. Insert and delete take O(log2n) amortized time

  22. How do we make this a parametric heap ?(Overmars-Van Leeuwen)

  23. c d b e a d e c b a 3 2 5 4 1 7 6

  24. Looks like we use non linear space ? Each node keeps the chain of segments that are on its envelope but not on its parent envelope. This makes the space linear.

  25. c d b e a d e c b a 3 2 5 4 1 7 6

  26. Analysis Using search trees to represent the envelopes sorted by slopes then: Find-min takes O(log n) time Insert and delete take O(log2 n) time: You split and concatenate O(log n) such envelopes.

  27. Balanced kinetic heaps Plan: first we’ll do only deletions faster and then we’ll add insertions. Our starting point is the previous data structure. Def: The level of a line is the depth of the highest node where it is stored.

  28. Deletion-only data structure The level of a line is the depth of the highest node where it is stored.

  29. c d b e a d d e c b a 3 2 5 4 1 7 6

  30. Deletion-only data structure What happens when we delete a line ?

  31. c d b e a d d e c b a 3 2 5 4 1 7 6

  32. c d b e a e d d b a 3 2 5 4 1 7 6

  33. c d b e a e d d b a 3 2 5 4 1 7 6

  34. c d b e d a e d b a 3 2 5 4 1 7 6

  35. Balanced kinetic heaps When we delete a line, lines only decrease their level.

  36. 3 2 5 4 1 7 6

  37. 3 2 5 4 1 7 6

  38. Analysis Key idea: Implement the envelopes using finger search trees How much time it takes to delete an element ? O(log n) + log (# lines get on the replacement piece) + log (# lines get off the replacement piece) If in all nodes # lines get on/off the replacement piece < log2n we are ok --- the delete takes O(log n loglog n) time However it could be that # lines get on/off the replacement piece > log2n

  39. Analysis (Cont) If a line gets on the replacement piece it changes its level Since the total number of level changes is nlog(n) The number of chains of length > log2n is at most n/log(n) So the total work in moving long chain is O(n) and can be charged to the initialization phase.

  40. Summary so far A better deletions only data structure O(n) init. time and then O(log n loglog n) per delete. O(1) find-min if we are kinetic. Now we add insert.

  41. Balanced kinetic heaps (finalle) Balanced heaps (step 2): Use a well known reduction by Bently and Saxe to add insertions . . . . . . . . . . . . . . Maintain a binary counter of deletion only data structures

  42. . . . . . . . . . . . . . . Balanced kinetic heaps Delete : O(log n loglog n) Insert : O(log n) Find-min : O(log n) (kinetic)

  43. Fibonacci heap (highlights) Based one Fibonacci heaps with lazy linking. We link only when it is safe We get O(log2 n) for delete O(log n) for find-min and insert O(log n) for decrease-key

  44. Fibonacci heaps (Fredman & Tarjan 84) Want to do decrease-key(x,h,) faster than delete+insert. ( in O(1) time.)

  45. 5 2 1 5 5 5 6 6 8 9 10 Heap ordered (Fibonacci) trees

  46. 5 1 5 5 2 6 6 4 10 6 8 9 9 11 9 10 Linking Operations are defined via a basic operation, called linking, of Fibonacci trees: Produce a Fk from two Fk-1, keep heap order.

  47. Regular heap Basic idea: delay the linking until they are safe S0 S1 Sr . . . .

  48. Linking The basic operation is inserting a tree of rank r into Sr, making the appropriate linking if needed. This may cascade, but we have one tree less every time we do the linking Insert(i) : Insert a new node containing i into S0 Decrease-key(i, a’.b’) : Decrease the key of i in the tree containing it making cascading cuts, link the resulting trees back into the structure.

  49. Analysis Similar to the analysis of F-heaps Multiply the potential by log n

  50. Incremental heap (highlights) Assumptions insertion of i: ai = 1, increase key of i: ai :=ai + 1 Group items by key slope, each group is an ordinary Fibonacci heap Move items among groups as key slopes change (“displaced” items because entire subtrees are moved) We get find-max, insert : O(1) The kth increase-key : O(log min{k,n}) delete : O(log n)

More Related