Quake Heap
| Quake Heap | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Type | heap | ||||||||||||||||||||||||
| Invented | 2013 | ||||||||||||||||||||||||
| Invented by | Timothy M. Chan | ||||||||||||||||||||||||
| Time complexity in big O notation | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
A Quake heap is a data structure that implements the basic priority queue operations: insert, delete-min, union, and decrease-key. A Quake heap must satisfy the following properties:
- The data structure follows the heap-ordering properties
- Each internal node has a pointer to the smallest node amongst its children
- All paths from a node x to a leaf node are the same length; this length is denoted as the height at x
- Internal nodes have a degree of 1 or 2
The data structure has similaramortized running times for each of the supported operations as a Fibonacci heap but Fibonacci heaps require more nuanced understanding of the intermediate structures that form and inductive proofs in order to perform the analysis. Quake heaps, by contrast, avoid using techniques like marking nodes to be cut and as a result are much more straightforward to anaylze, assuming only a basic familiarity with amortized analysis. As such, quake heaps are well suited for educational environments to help students understand the process behind analyzing runtime complexities and are much simpler to implement.
Much like a Fibonacci heap, a quake heap relies on storing the individual trees within the heap in a list and performs the same linking process during the delete-min() operation. Instead of storing them by their degree, however, they store them by their heights and link them in the same fashion.
Structure
While quake heaps are less flexible in the shapes that are allowed due to the properties of the data structure, they are much simpler than a Fibonacci heap. Similarly, quake heaps are collections of rooted subtrees. They differ in that a quake heap resembles a tournament bracket where the smallest element is the winner and elements may receive a bye throughout the tournament in order to advance in the tree. In essence the winner of the tournament is the smallest number within its tree. A quake heap may have numerous trees contained within it, however, so the root of a tree is not the smallest element within the heap itself.
Quake heaps perform lazy updates which often lead to unideal To avoid imbalance, an invariant is followed:
- Let ni be the number of nodes at height i
- For some constant
Implementation of operations
In order to insert an element x into the heap, we simply create a new node and insert it into a new tree. This results in a new tree of degree 0 composed solely of a node with value x.
To support decrease-key acting on element x and decreasing its priority to a value of k there are some significant departures from a Fibonacci heap. While the internal nodes are pointers to the smallest child node, and could thus be changed in one step, simply decreasing the key would cause a costly chains of updates since each level of the tree would need to be recalculated to ensure that the second property of quake heaps is upheld. Instead, the subtree at x is cut, causing a new tree is created, and the cut nodes pointer has its value updated to k. Lots of Decrease-Key operations may result in a tree with many tall branches; an invariant is introduced to maintain the data-structure during delete-min()
If we invalidate the invariant during delete-min(), we delete all nodes above the lowest i violation in all trees. This imposes a constraint on the height of the tree such that the maximum height is
The steps for delete-min() are as follows:
- Cut the path containing the minimum element
- Merge trees of the same size, similar to Fibonacci Heap
- Resolve invariant by removing necessary nodes
To perform a union or meld between two trees:
- Clone the smallest root of between the two trees, x and y
- Set the roots of x and y to be the children of the cloned node
Cost Analysis
Defining the Potential Function
The state of our data structure can largely be represented by three quantities, the number of nodes (since larger nodes means larger graphs to traverse in order to get to the roots), the number of trees (in order to iterate to get the minimum value, or to link during delete-min), and the number of degree-1 nodes (since they are artifacts from operations that only seek to increase the runtime of root-finding components of the data structure).
Let N be the number of nodes
Let T be the number of trees
Let B be the number of degree-1 nodes
The potential function can be described as thus:
For simplicity, , thus
Insert(x)
Psuedocode:
1. create a new tree containing x
Impact on potential function:
Actual cost is
Decrease-Key(x, k)
Pseudocode:
1. cut the subtree rooted at the highest node storing x 2. change x’s value to k
Impact on potential function:
Actual cost is
Delete-Min()
Pseudocode:
1. x ← minimum of all the roots 2. remove the path of nodes storing x 3. while there are 2 trees of the same height: 4. link the 2 trees 5. if ni+1 > ni for some i then: 6. let i be the smallest such index 7. remove all nodes at heights > i 8. return x
Impact on potential function:
Maximum height, O(log n); Actual cost = T + O(log n)
Union(x, y)
Pseudocode:
1. clone the node with the smaller value between x and y’s roots 2. set x and y’s roots to point to the clone
Impact on potential function:
Actual cost is
| Operation | Actual Cost | Amortized Cost | |
|---|---|---|---|
| insert(x) | O(1) | 2 | O(1) > 0 |
| decrease-key(x, k) | O(1) | 3 | O(1) > 0 |
| delete-min() | O(log n) | < 0 | O(log n) |
| union(x, y) | O(1) | 0 | O(1) > 0 |
The negative for delete-min() implies that the decrease of the potential of the data structure is paying the difference; it's actual cost is still bounded by O(log n). Since the amortized costs are constant values and we assume we start with an empty structure, the complexity of Quake Heaps falls under the O(log n) category.
Summary of Heap Running Times
Here are time complexities[1] of various heap data structures. Function names assume a min-heap. For the meaning of "O(f)" and "Θ(f)" see Big O notation.
| Operation | find-min | delete-min | insert | decrease-key | meld |
|---|---|---|---|---|---|
| Binary[1] | Θ(1) | Θ(log n) | O(log n) | O(log n) | Θ(n) |
| Leftist | Θ(1) | Θ(log n) | Θ(log n) | O(log n) | Θ(log n) |
| Binomial[1][2] | Θ(1) | Θ(log n) | Θ(1)[lower-alpha 1] | Θ(log n) | O(log n)[lower-alpha 2] |
| Fibonacci[1][3] | Θ(1) | O(log n)[lower-alpha 1] | Θ(1) | Θ(1)[lower-alpha 1] | Θ(1) |
| Pairing[4] | Θ(1) | O(log n)[lower-alpha 1] | Θ(1) | o(log n)[lower-alpha 1][lower-alpha 3] | Θ(1) |
| Brodal[7][lower-alpha 4] | Θ(1) | O(log n) | Θ(1) | Θ(1) | Θ(1) |
| Rank-pairing[9] | Θ(1) | O(log n)[lower-alpha 1] | Θ(1) | Θ(1)[lower-alpha 1] | Θ(1) |
| Strict Fibonacci[10] | Θ(1) | O(log n) | Θ(1) | Θ(1) | Θ(1) |
| 2–3 heap[11] | O(log n) | O(log n)[lower-alpha 1] | O(log n)[lower-alpha 1] | Θ(1) | ? |
| Quake Heap[12] | Θ(1) | O(log n)[lower-alpha 1] | Θ(1) | Θ(1) | Θ(1) |
- ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 Amortized time.
- ↑ n is the size of the larger heap.
- ↑ Lower bound of [5] upper bound of [6]
- ↑ Brodal and Okasaki later describe a persistent variant with the same bounds except for decrease-key, which is not supported. Heaps with n elements can be constructed bottom-up in O(n).[8]
References
- ↑ 1.0 1.1 1.2 1.3 Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L. (1990). Introduction to Algorithms (1st ed.). MIT Press and McGraw-Hill. ISBN 0-262-03141-8. Search this book on
- ↑ "Binomial Heap | Brilliant Math & Science Wiki". brilliant.org. Retrieved 2019-09-30.
- ↑ Fredman, Michael Lawrence; Tarjan, Robert E. (July 1987). "Fibonacci heaps and their uses in improved network optimization algorithms" (PDF). Journal of the Association for Computing Machinery. 34 (3): 596–615. CiteSeerX 10.1.1.309.8927. doi:10.1145/28869.28874. Archived from the original (PDF) on 2019-07-12. Retrieved 2023-06-07.
- ↑ Iacono, John (2000), "Improved upper bounds for pairing heaps", Proc. 7th Scandinavian Workshop on Algorithm Theory (PDF), Lecture Notes in Computer Science, 1851, Springer-Verlag, pp. 63–77, arXiv:1110.4428, CiteSeerX 10.1.1.748.7812, doi:10.1007/3-540-44985-X_5, ISBN 3-540-67690-2, archived from the original (PDF) on 2012-12-24, retrieved 2023-06-07
- ↑ Fredman, Michael Lawrence (July 1999). "On the Efficiency of Pairing Heaps and Related Data Structures" (PDF). Journal of the Association for Computing Machinery. 46 (4): 473–501. doi:10.1145/320211.320214.
- ↑ Pettie, Seth (2005). Towards a Final Analysis of Pairing Heaps (PDF). FOCS '05 Proceedings of the 46th Annual IEEE Symposium on Foundations of Computer Science. pp. 174–183. CiteSeerX 10.1.1.549.471. doi:10.1109/SFCS.2005.75. ISBN 0-7695-2468-0.
- ↑ Brodal, Gerth S. (1996), "Worst-Case Efficient Priority Queues" (PDF), Proc. 7th Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 52–58
- ↑ Goodrich, Michael T.; Tamassia, Roberto (2004). "7.3.6. Bottom-Up Heap Construction". Data Structures and Algorithms in Java (3rd ed.). pp. 338–341. ISBN 0-471-46983-1. Search this book on
- ↑ Haeupler, Bernhard; Sen, Siddhartha; Tarjan, Robert E. (November 2011). "Rank-pairing heaps" (PDF). SIAM J. Computing. 40 (6): 1463–1485. doi:10.1137/100785351.
- ↑ Brodal, Gerth Stølting; Lagogiannis, George; Tarjan, Robert E. (2012). Strict Fibonacci heaps (PDF). Proceedings of the 44th symposium on Theory of Computing - STOC '12. pp. 1177–1184. CiteSeerX 10.1.1.233.1740. doi:10.1145/2213977.2214082. ISBN 978-1-4503-1245-5.
- ↑ Takaoka, Tadao (1999), Theory of 2–3 Heaps (PDF), p. 12
- ↑ Chan, Timothy (2013), Quake Heaps: A Simple Alternative to Fibonacci Heaps (PDF), p. 6
This article "Quake Heap" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Quake Heap. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
