Quake Heaps: A Simple Alternative to Fibonacci Heaps

Similar documents
Rank-Pairing Heaps. Bernard Haeupler Siddhartha Sen Robert E. Tarjan. SIAM JOURNAL ON COMPUTING Vol. 40, No. 6 (2011), pp.

RANK-PAIRING HEAPS BERNHARD HAEUPLER 1, SIDDHARTHA SEN 2,4, AND ROBERT E. TARJAN 3,4

Rank-Pairing Heaps. Some applications of heaps need either or both of the following additional operations.

arxiv: v2 [cs.ds] 9 Apr 2009

Hollow Heaps. Aarhus University, Denmark. Tel Aviv University, Israel. Princeton University, USA. July 7, 2015

Priority Queues. Meld(Q 1,Q 2 ) merge two sets

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

Are Fibonacci Heaps Optimal? Diab Abuaiadh and Jeffrey H. Kingston ABSTRACT

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

Sorting and Searching

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Sorting and Searching

CS711008Z Algorithm Design and Analysis

Advanced Algorithms. Class Notes for Thursday, September 18, 2014 Bernard Moret

CS711008Z Algorithm Design and Analysis

CSE 5311 Notes 4a: Priority Queues

On the power of structural violations in priority queues

On the other hand, the main disadvantage of the amortized approach is that it cannot be applied in real-time programs, where the worst-case bound on t

Binary heaps (chapters ) Leftist heaps

CSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )

Binary Heaps in Dynamic Arrays

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013

Chapter 6 Heapsort 1

Fibonacci Heaps. Structure. Implementation. Implementation. Delete Min. Delete Min. Set of min-heap ordered trees min

V Advanced Data Structures

ADAPTIVE SORTING WITH AVL TREES

Analysis of Algorithms

W4231: Analysis of Algorithms

B-Trees. Version of October 2, B-Trees Version of October 2, / 22

Faster, Space-Efficient Selection Algorithms in Read-Only Memory for Integers

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn

Lecture 5 Using Data Structures to Improve Dijkstra s Algorithm. (AM&O Sections and Appendix A)

Algorithms and Data Structures. (c) Marcin Sydow. Priority Queue. Example Applications. Extensions of. Priority Queue. Binomial Heap.

18.3 Deleting a key from a B-tree

V Advanced Data Structures

Melding priority queues

Towards ultimate binary heaps

Multi-Way Search Trees

Three Sorting Algorithms Using Priority Queues

Multi-Way Search Trees

Heap-on-Top Priority Queues. March Abstract. We introduce the heap-on-top (hot) priority queue data structure that combines the

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Chapter 6 Heaps. Introduction. Heap Model. Heap Implementation

CSE 530A. B+ Trees. Washington University Fall 2013

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1.

Recall: Properties of B-Trees

FIBONACCI HEAPS. preliminaries insert extract the minimum decrease key bounding the rank meld and delete. Lecture slides by Kevin Wayne

Path Minima Queries in Dynamic Weighted Trees

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

CSE373: Data Structures & Algorithms Lecture 9: Priority Queues. Aaron Bauer Winter 2014

Lecture Summary CSC 263H. August 5, 2016

Priority Queues and Binary Heaps

Review of 4 comparison-based priority queues: Binary, Binomial, Fibonacci and Weak heap : Technical report LUSY-2012/01

HEAPS ON HEAPS* Downloaded 02/04/13 to Redistribution subject to SIAM license or copyright; see

Hollow Heaps. Thomas Dueholm Hansen Haim Kaplan Robert E. Tarjan Uri Zwick

Advanced Set Representation Methods

Laboratory Module X B TREES

A Distribution-Sensitive Dictionary with Low Space Overhead

Analysis of Algorithms

CSCI2100B Data Structures Heaps

CS 240 Fall Mike Lam, Professor. Priority Queues and Heaps

Lecture Notes for Advanced Algorithms

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

Let the dynamic table support the operations TABLE-INSERT and TABLE-DELETE It is convenient to use the load factor ( )

Dynamic Access Binary Search Trees

Properties of red-black trees

Heap Model. specialized queue required heap (priority queue) provides at least

Dynamic Access Binary Search Trees

Chapter 2: Basic Data Structures

3 Competitive Dynamic BSTs (January 31 and February 2)

Algorithm Theory, Winter Term 2015/16 Problem Set 5 - Sample Solution

Abstract Relaxed balancing of search trees was introduced with the aim of speeding up the updates and allowing a high degree of concurrency. In a rela

Red-black tree. Background and terminology. Uses and advantages

Priority queue. Advanced Algorithmics (6EAP) MTAT Heaps. Binary heap. Heap/Priority queue. Binomial heaps:

Heaps Goodrich, Tamassia. Heaps 1

SKEW HEAPS: Self-Adjusting Heaps

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

Heaps. 2/13/2006 Heaps 1

Soft Heaps And Minimum Spanning Trees

Expected Time in Linear Space

Chapter 4: Trees. 4.2 For node B :

CSE100. Advanced Data Structures. Lecture 8. (Based on Paul Kube course materials)

CS166 Handout 11 Spring 2018 May 8, 2018 Problem Set 4: Amortized Efficiency

Questions from the material presented in this lecture

HEAPS: IMPLEMENTING EFFICIENT PRIORITY QUEUES

Balanced Search Trees. CS 3110 Fall 2010

CS 240 Data Structures and Data Management. Module 2: Priority Queues

CS 240 Data Structures and Data Management. Module 2: Priority Queues

UNIT III BALANCED SEARCH TREES AND INDEXING

Lecture 8 13 March, 2012

Priority Queues. 1 Introduction. 2 Naïve Implementations. CSci 335 Software Design and Analysis III Chapter 6 Priority Queues. Prof.

Balanced Binary Search Trees. Victor Gao

Lecture 6: Analysis of Algorithms (CS )

Heaps 2. Recall Priority Queue ADT. Heaps 3/19/14

Heaps Outline and Required Reading: Heaps ( 7.3) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Section 4 SOLUTION: AVL Trees & B-Trees

9. Heap : Priority Queue

The Unified Segment Tree and its Application to the Rectangle Intersection Problem

Transcription:

Quake Heaps: A Simple Alternative to Fibonacci Heaps Timothy M. Chan Cheriton School of Computer Science, University of Waterloo, Waterloo, Ontario N2L G, Canada, tmchan@uwaterloo.ca Abstract. This note describes a data structure that has the same theoretical performance as Fibonacci heaps, supporting decrease-key operations in O() amortized time and delete-min operations in O(log n) amortized time. The data structure is simple to explain and analyze, and may be of pedagogical value. Introduction In their seminal paper [5], Fredman and Tarjan investigated the problem of maintaining a set S of n elements under the operations insert(x): insert an element x to S; delete-min(): remove the minimum element x from S, returning x; decrease-key(x, k): change the value of an element x toasmallervaluek. They presented the first data structure, called Fibonacci heaps, that can support insert() and decrease-key() in O() amortized time, and delete-min() in O(log n) amortized time. Since Fredman and Tarjan s paper, a number of alternatives have been proposed in the literature, including Driscoll et al. s relaxed heaps and run-relaxed heaps [], Peterson s Vheaps [9], which is based on AVL trees (and is an instance of Høyer s family of ranked priority queues [7]), Takaoka s 2- heaps [], Kaplan and Tarjan s thin heaps and fat heaps [8], Elmasry s violation heaps [2], and most recently, Haeupler, Sen, and Tarjan s rank-pairing heaps [6]. The classical pairing heaps [, 0, ] are another popular variant that performs well in practice, although they do not guarantee O() decrease-key cost. Among all the data structures that guarantee constant decrease-key and logarithmic delete-min cost, Fibonacci heaps have remained the most popular to teach. The decrease-key operation uses a simple cascading cut strategy, which requires an extra bit per node for marking. For the analysis, the potential function itself is not complicated, but one needs to first establish bounds on the maximum degree of the trees (Fibonacci numbers come into play here), and this requires understanding some subtle structural properties of the trees formed (a node may lose at most one child when it is not a root, but may lose multiple children when it is a root). In contrast, Vheaps are more straightforward to analyze, for those already acquainted with AVL trees, but the decrease-key() algorithm

requires division into multiple cases, like the update algorithms of most balanced search trees. The recent rank-pairing heaps interestingly avoid cascading cuts by performing cascading rank changes, which may lead to a simpler implementation, but from the teaching perspective, the analysis appears even more complicated than for Fibonacci heaps (and there are also divisions into multiple cases). In this note, we describe a data structure that is arguably the easiest to understand among all the existing methods. There is no case analysis involved, and no cascading during decrease-key(). We use a very simple, and rather standard, idea to ensure balance: be lazy during updates, and just rebuild when the structure gets bad. Previous methods differ based on what local structural invariants are imposed. Our method is perhaps the most relaxed, completely forgoing local constraints, only requiring the tracking of some global counters. (Violation heaps [2] are of a similar vein but require multiple local counters; our method is simpler.) In Section 2, we give a self-contained presentation of our method, which should be helpful for classroom use; it only assumes basic knowledge of amortized analysis. We find a description based on tournament trees the most intuitive, although the data structure can also be expressed more traditionally in terms of heap-ordered trees or half-ordered trees, as noted in Section. 2 Quake Heaps The approach. We will work with a collection of tournament trees, whereeach element in S is stored in exactly one leaf, and the element of each internal node is defined as the minimum of the elements at the children. We require that at each node x, all paths from x to a leaf have the same length; this length is referred to as the height of x. We also require that each internal node has degree 2 or. See Figure. 5 2 0 5 2 6 9 6 5 0 5 8 2 Fig.. An example. Two basic operations are easy to do in constant time under these requirements: First, given two trees of the same height, we can link them into one, Tradition demands a name to be given. The one in the title will hopefully make some sense after reading Section 2.

simply by creating a new root pointing to the two roots, storing the smaller element among the two roots. Secondly, given a node x whose element is different from x s parent s, we can cut out the subtree rooted at x. Notethatx s former parent s degree is reduced to, but our setup explicitly allows for degree- nodes. Inserting an element can be trivially done by creating a new tree of size. The number of trees in the collection increases by, but can be reduced by linking at a convenient time later. For a delete-min operation, we can just remove the path of nodes that store the minimum element. The number of trees in the collection grows, and this is the time to do repeated linking operations to reduce the number of trees. Namely, whenever there are two trees of the same height, we link them. For a decrease-key operation on an element, let x be the highest node that stores the element. It would be too costly to update the elements at all the ancestors of x. Instead we can perform a cut at x. Then we can decrease the value of x at will in the separate new tree. We need to address one key issue: after many decrease-key operations, the trees may become too off-balanced. Let n i denote the number of nodes at height i. (In particular, n 0 = n = S.) Our approach is simple we maintain the following invariant for some fixed constant α (/2, ): n i+ αn i. (To be concrete, we can set α = /, for example.) The invariant clearly implies that the maximum height is at most log /α n. When the invariant is violated for some i, a seismic event occurs and we remove everything from height i + and up, to allow rebuilding later. Since n i+ = n i+2 = = 0 now, the invariant is restored. Intuitively, events of large magnitude (i.e., events at low heights i) should occur infrequently. Pseudocode. We give pseudocode for all three operations below: insert(x):. create a new tree containing {x} decrease-key(x, k):. cut the subtree rooted at the highest node storing x [yields new tree] 2. change x s value to k delete-min():. x minimum of all the roots 2. remove the path of nodes storing x [yields multiple new trees]. while there are 2 trees of the same height:. link the 2 trees [reduces the number of trees by ] 5. if n i+ >αn i for some i then: 6. let i be the smallest such index 7. remove all nodes at heights >i [increases the number of trees] 8. return x

We can explicitly maintain a pointer to the highest node storing x for each element x; it is easy to update these pointers as linkings are performed. It is also easy to update the n i s as nodes are created and removed. Lines in delete-min() can be done in time proportional to the current number of trees, by using an auxiliary array of pointers to trees indexed by their heights. Analysis. In the current data structure, let N be the number of nodes, T be the number of trees, and B be the number of degree- nodes (the bad nodes). Define the potential to be N + T + 2α B. The amortized cost of an operation is the actual cost plus the change in potential. For insert(), the actual cost is O(), and N and T increase by. So, the amortized cost is O(). For decrease-key(), the actual cost is O(), and T and B increase by. So, the amortized cost is O(). For delete-min(), we analyze lines first. Let T (0) be the value of T just before the operation. Recall that the maximum height, and thus the length of the path in line 2, is O(log n). We can bound the actual cost by T (0) + O(log n). Since after lines there can remain at most one tree per height, T is decreased to O(log n). So, the change in T is O(log n) T (0). Since linking does not create degree- nodes, the change in B is nonpositive. Thus, the amortized cost is O(log n). For lines 5 7 of delete-min(), let n (0) j be the value of n j just before these lines. We can bound the actual cost of lines 5 7 by j>i n(0) j. The change in N is at most j>i n(0) j. The change in T is at most +n (0) i.letb (0) i be the number of degree- nodes at height i just before lines 5 7. Observe that n (0) i 2n (0) i+ b(0) i.thus,b (0) i 2n (0) i+ n(0) i (2α )n (0) i. Hence, the change in B is at most (2α )n (0) i. Thus, the net change in T + 2α B is nonpositive. We conclude that the amortized cost of lines 5 7 is nonpositive. Therefore, the overall amortized cost for delete-min() is O(log n). Comments Like Fibonacci heaps, our method can easily support the meld (i.e., merge) operation in O() amortized time, by just concatenating the lists of trees. Many variations of the method are possible. Linking of equal-height trees can be done at other places, for example, immediately after an insertion or after lines 5 7 of delete-min(), without affecting the amortized cost. Alternatively, we can perform less linking in lines of delete-min(), as long as the number of trees is reduced by a fraction if it exceeds Θ(log n). We can further relax the invariant to n i+c αn i for any integer constant c. In the analysis, the potential can be readjusted to N + T + c(2α ) B.Itis straightforward to check that the amortized number of comparisons per decreasekey()isatmost+ c(2α ), which can be made arbitrarily close to at the

expense of increasing the constant factor in delete-min(). (A similar tradeoff of constant factors is possible with Fibonacci heaps as well, by relaxing the lose at most one child per node property to at most c children [5].) In the tournament trees, it is convenient to assume that the smaller child of each node is always the left child (and if the node has degree, its only child is the left child). 9 6 2 6 2 5 2 9 6 2 6 5 9 6 6 5 Fig. 2. Transforming a tournament tree into a heap-ordered tree or a half-ordered tree. The tournament trees require a linear number of extra nodes, but more spaceefficient representations are possible where each element is stored in only one node. One option is to transform each tournament tree T into a heap-ordered, O(log n)-degree tree T : the children of x in T are the right children of all the nodes storing x in T. See Figure 2 (middle). Binomial heaps and Fibonacci heaps are usually described for trees of this form. Another option is to transform T into a binary tree T as follows: after shortcutting degree- nodes in T, the right child of x in T is the right child of the highest node storing x in T ; the left child of x in T is the right child of the sibling of the highest node storing x in T. See Figure 2 (right). The resulting tree T is a half-ordered binary tree: the value of every node x is smaller than the value of any node in the right subtree of x. Høyer [7] advocated the use of such trees in implementation. It is straightforward to redescribe our method in terms of half-ordered binary trees. For example, see [7] on the analogous linking and cutting operations. While our method is simple to understand conceptually, we do not claim that it would lead to the shortest code, nor the fastest implementation in practice, compared to existing methods. Philosophically, Peterson s and Høyer s work demonstrated that a heap data structure supporting decrease-key() in constant amortized time can be obtained from techniques for balanced search trees supporting deletions in constant amortized time. The moral of this note is that the heap problem is in fact simpler than balanced search trees a very simple lazy update algorithm suffices to ensure balance for heaps. References. J. Driscoll, H. Gabow, R. Shrairman, and R. Tarjan. Relaxed heaps: an alternative to Fibonacci heaps with applications to parallel computation. Commun. ACM,

: 5, 988. 2. A. Elmasry. The violation heap: a relaxed Fibonacci-like heap. Discrete Math., Alg. and Appl., 2:9 50, 0.. A. Elmasry. Pairing heaps with O(log log n) decrease cost. In Proc. th ACM SIAM Sympos. Discrete Algorithms, pages 7 76, 09.. M. Fredman, R. Sedgewick, D. Sleator, and R. Tarjan. The pairing heap: a new form of self-adjusting heap. Algorithmica, : 29, 986. 5. M. Fredman and R. Tarjan. Fibonacci heaps and their uses in improved network optimization algorithms. J. ACM, :596 65, 987. 6. B. Haeupler, S. Sen, and R. E. Tarjan. Rank-pairing heaps. SIAM J. Comput., 0:6 85,. 7. P. Høyer. A general technique for implementation of efficient priority queues. In Proc. rd Israel Sympos. Theory of Comput. Sys., pages 57 66, 995. 8. H. Kaplan and R. Tarjan. Thin heaps, thick heaps. ACM Trans. Algorithms, ():, 08. 9. G. Peterson. A balanced tree scheme for meldable heaps with updates. Tech. Report GIT-ICS-87-2, Georgia Institute of Technology, 987. 0. S. Pettie. Towards a final analysis of pairing heaps. In Proc. 6th IEEE Sympos. Found. Comput. Sci., pages 7 8, 05.. T. Takaoka. Theory of 2- heaps. Discrete Applied Math., 26:5 28, 0.