Shadow heap

Last updated

In computer science, a shadow heap is a mergeable heap data structure which supports efficient heap merging in the amortized sense. More specifically, shadow heaps make use of the shadow merge algorithm to achieve insertion in O(f(n)) amortized time and deletion in O((log n log log n)/f(n)) amortized time, for any choice of 1 ≤ f(n) ≤ log log n. [1]

Computer science study of the theoretical foundations of information and computation

Computer science is the study of mathematical algorithms and processes that interact with data and that can be represented as data in the form of programs. It enables the use of algorithms to manipulate, store, and communicate digital information. A computer scientist studies the theory of computation and the practice of designing software systems.

In computer science, a mergeable heap is an abstract data type, which is a heap supporting a merge operation.

Data structure particular way of storing and organizing data in a computer

In computer science, a data structure is a data organization, management and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.

Contents

Throughout this article, it is assumed that A and B are binary heaps with |A| ≤ |B|.

Shadow merge

Shadow merge is an algorithm for merging two binary heaps efficiently if these heaps are implemented as arrays. Specifically, the running time of shadow merge on two heaps and is .

Algorithm an unambiguous specification of how to solve a class of problems

In mathematics and computer science, an algorithm is an unambiguous specification of how to solve a class of problems. Algorithms can perform calculation, data processing, and automated reasoning tasks.

Binary heap heap data structure that takes the form of a binary tree

A binary heap is a heap data structure that takes the form of a binary tree. Binary heaps are a common way of implementing priority queues. The binary heap was introduced by J. W. J. Williams in 1964, as a data structure for heapsort.

In computer science, an array data structure, or simply an array, is a data structure consisting of a collection of elements, each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple by a mathematical formula. The simplest type of data structure is a linear array, also called one-dimensional array.

Algorithm

We wish to merge the two binary min-heaps and . The algorithm is as follows:

  1. Concatenate the array at the end of the array to obtain an array .
  2. Identify the shadow of in ; that is, the ancestors of the last nodes in which destroy the heap property.
  3. Identify the following two parts of the shadow from :
    • The path: the set of nodes in the shadow for which there are at most 2 at any depth of ;
    • The subtree: the remainder of the shadow.
  4. Extract and sort the smallest nodes from the shadow into an array .
  5. Transform as follows:
    • If , then starting from the smallest element in the sorted array, sequentially insert each element of into , replacing them with 's smallest elements.
    • If , then extract and sort the smallest elements from , and merge this sorted list with .
  6. Replace the elements of into their original positions in .
  7. Make a heap out of .

Running time

Again, let denote the path, and denote the subtree of the concatenated heap . The number of nodes in is at most twice the depth of , which is . Moreover, the number of nodes in at depth is at most 3/4 the number of nodes at depth , so the subtree has size . Since there are at most 2 nodes at each level on , then reading the smallest elements of the shadow into the sorted array takes time.

If , then combining and as in step 5 above takes time . Otherwise, the time taken in this step is . Finally, making a heap of the subtree takes time. This amounts to a total running time for shadow merging of .

Structure

A shadow heap consists of threshold function , and an array for which the usual array-implemented binary heap property is upheld in its first entries, and for which the heap property is not necessarily upheld in the other entries. Thus, the shadow heap is essentially a binary heap adjacent to an array . To add an element to the shadow heap, place it in the array . If the array becomes too large according to the specified threshold, we first build a heap out of using Floyd's algorithm for heap construction, [2] and then merge this heap with using shadow merge. Finally, the merging of shadow heaps is simply done through sequential insertion of one heap into the other using the above insertion procedure.

Analysis

We are given a shadow heap , with threshold function as above. Suppose that the threshold function is such that any change in induces no larger a change than in . We derive the desired running time bounds for the mergeable heap operations using the potential method for amortized analysis. The potential of the heap is chosen to be:

In computational complexity theory, the potential method is a method used to analyze the amortized time and space complexity of a data structure, a measure of its performance over sequences of operations that smooths out the cost of infrequent but expensive operations.

In computer science, amortized analysis is a method for analyzing a given algorithm's complexity, or how much of a resource, especially time or memory, it takes to execute. The motivation for amortized analysis is that looking at the worst-case run time per operation, rather than per algorithm, can be too pessimistic.

Using this potential, we can obtain the desired amortized running times:

create(H): initializes a new empty shadow heap

Here, the potential is unchanged, so the amortized cost of creation is , the actual cost.

insert(x, H): inserts into the shadow heap

There are two cases:
  • If the merge is employed, then the drop in the potential function is exactly the actual cost of merging and , so the amortized cost is .
  • If the merge is not done, then the amortized cost is
By choice of the threshold function, we thus obtain that the amortized cost of insertion is:

delete_min(H): deletes the minimum priority element from

Finding and deleting the minimum takes actual time . Moreover, the potential function can only increase after this deletion if the value of decreases. By choice of , we have that the amortized cost of this operation is the same as the actual cost.

A naive binary heap merging algorithm will merge the two heaps and in time by simply concatenating both heaps and making a heap out of the resulting array using Floyd's algorithm for heap construction. Alternatively, the heaps can simply be merged by sequentially inserting each element of into , taking time .

Sack and Strothotte proposed an algorithm for merging the binary heaps in time. [3] Their algorithm is known to be more efficient than the second naive solution described above roughly when . Shadow merge performs asymptotically better than their algorithm, even in the worst case.

Jörg-Rüdiger Sack German computer scientist

Jörg-Rüdiger Wolfgang Sack is a professor of computer science at Carleton University, where he holds the SUN–NSERC chair in Applied Parallel Computing. Sack received a master's degree from the University of Bonn in 1979 and a Ph.D. in 1984 from McGill University, under the supervision of Godfried Toussaint. He is co-editor-in-chief of the journals Computational Geometry: Theory and Applications and the Journal of Spatial Information Science, co-editor of the Handbook of Computational Geometry, and co-editor of the proceedings of the biennial Algorithms and Data Structures Symposium (WADS). Sack's research interests include computational geometry, parallel algorithms, and geographic information systems.

Thomas Strothotte Canadian computer scientist

Thomas Strothotte is a German-Canadian computer scientist and university administrator living in Germany. He is the President of the Kühne Logistics University in Hamburg.

There are several other heaps which support faster merge times. For instance, Fibonacci heaps can be merged in time. Since binary heaps require time to merge, [4] shadow merge remains efficient.

Related Research Articles

AVL tree one kind of self-balancing binary search tree

In computer science, an AVL tree is a self-balancing binary search tree. It was the first such data structure to be invented. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property. Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases, where is the number of nodes in the tree prior to the operation. Insertions and deletions may require the tree to be rebalanced by one or more tree rotations.

Binary search tree data structure in tree form with 0, 1, or 2 children per node, sorted for fast lookup

In computer science, binary search trees (BST), sometimes called ordered or sorted binary trees, are a particular type of container: data structures that store "items" in memory. They allow fast lookup, addition and removal of items, and can be used to implement either dynamic sets of items, or lookup tables that allow finding an item by its key.

Heap (data structure) tree-based data structure in computer science

In computer science, a heap is a specialized tree-based data structure which is essentially an almost complete tree that satisfies the heap property: if P is a parent node of C, then the key of P is either greater than or equal to or less than or equal to the key of C. The node at the "top" of the heap is called the root node.

In computer science, a priority queue is an abstract data type which is like a regular queue or stack data structure, but where additionally each element has a "priority" associated with it. In a priority queue, an element with high priority is served before an element with low priority. In some implementations, if two elements have the same priority, they are served according to the order in which they were enqueued, while in other implementations, ordering of elements with the same priority is undefined.

In computer science, the treap and the randomized binary search tree are two closely related forms of binary search tree data structures that maintain a dynamic set of ordered keys and allow binary searches among the keys. After any sequence of insertions and deletions of keys, the shape of the tree is a random variable with the same probability distribution as a random binary tree; in particular, with high probability its height is proportional to the logarithm of the number of keys, so that each search, insertion, or deletion operation takes logarithmic time to perform.

In computer science, a binomial heap is a heap similar to a binary heap but also supports quick merging of two heaps. This is achieved by using a special tree structure. It is important as an implementation of the mergeable heap abstract data type, which is a priority queue supporting merge operation. Binomial heaps were invented in 1978 by J. Vuillemin.

In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the binary heap and binomial heap. Michael L. Fredman and Robert E. Tarjan developed Fibonacci heaps in 1984 and published them in a scientific journal in 1987. Fibonacci heaps are named after the Fibonacci numbers, which are used in their running time analysis.

Self-balancing binary search tree any node-based binary search tree that automatically keeps its height small

In computer science, a self-balancingbinary search tree is any node-based binary search tree that automatically keeps its height small in the face of arbitrary item insertions and deletions.

In computer science, a scapegoat tree is a self-balancing binary search tree, invented by Arne Andersson and again by Igal Galperin and Ronald L. Rivest. It provides worst-case O(log n) lookup time, and O(log n) amortized insertion and deletion time.

In computer science, an interval tree is a tree data structure to hold intervals. Specifically, it allows one to efficiently find all intervals that overlap with any given interval or point. It is often used for windowing queries, for instance, to find all roads on a computerized map inside a rectangular viewport, or to find all visible elements inside a three-dimensional scene. A similar data structure is the segment tree.

In computer science, a leftist tree or leftist heap is a priority queue implemented with a variant of a binary heap. Every node has an s-value which is the distance to the nearest leaf. In contrast to a binary heap, a leftist tree attempts to be very unbalanced. In addition to the heap property, leftist trees are maintained so the right descendant of each node has the lower s-value.

A pairing heap is a type of heap data structure with relatively simple implementation and excellent practical amortized performance, introduced by Michael Fredman, Robert Sedgewick, Daniel Sleator, and Robert Tarjan in 1986. Pairing heaps are heap-ordered multiway tree structures, and can be considered simplified Fibonacci heaps. They are considered a "robust choice" for implementing such algorithms as Prim's MST algorithm, and support the following operations :

The d-ary heap or d-heap is a priority queue data structure, a generalization of the binary heap in which the nodes have d children instead of 2. Thus, a binary heap is a 2-heap, and a ternary heap is a 3-heap. According to Tarjan and Jensen et al., d-ary heaps were invented by Donald B. Johnson in 1975.

In computer science, a min-max heap is a complete binary tree data structure which combines the usefulness of both a min-heap and a max-heap, that is, it provides constant time retrieval and logarithmic time removal of both the minimum and maximum elements in it. This makes the min-max heap a very useful data structure to implement a double-ended priority queue. Like binary min-heaps and max-heaps, min-max heaps support logarithmic insertion and deletion and can be built in linear time. Min-max heaps are often represented implicitly in an array; hence it's referred to as an implicit data structure.

Queap priority queue data structure

In computer science, a queap is a priority queue data structure. The data structure allows insertions and deletions of arbitrary elements, as well as retrieval of the highest-priority element. Each deletion takes amortized time logarithmic in the number of items that have been in the structure for a longer time than the removed item. Insertions take constant amortized time.

In computer science, the order-maintenance problem involves maintaining a totally ordered set supporting the following operations:

In computer science, k-way merge algorithms or multiway merges are a specific type of sequence merge algorithms that specialize in taking in multiple sorted lists and merging them into a single sorted list. These merge algorithms generally refer to merge algorithms that take in a number of sorted lists greater than two. 2-way merges are also referred to as binary merges.

A weak heap is a combination of the binary heap and binomial heap data structures for implementing priority queues. It can be stored in an array as an implicit binary tree like the former, and has the efficiency guarantees of the latter.

An oblivious data structure is a data structure that gives no information about the sequence or pattern of the operations that have been applied except for the final result of the operations.

References

  1. Kuszmaul, Christopher L. (2000). Efficient Merge and Insert Operations for Binary Heaps and Trees (PDF) (Technical report). NASA Advanced Supercomputing Division. 00-003.
  2. Suchenek, Marek A. (2012), "Elementary Yet Precise Worst-Case Analysis of Floyd's Heap-Construction Program", Fundamenta Informaticae, IOS Press, 120 (1): 75–92, doi:10.3233/FI-2012-751
  3. Sack, Jörg-R.; Strothotte, Thomas (1985), "An Algorithm for Merging Heaps", Acta Informatica, Springer-Verlag, 22 (2): 171–186, doi:10.1007/BF00264229 .
  4. 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.