HOME

TheInfoList



OR:

In computer science, a randomized meldable heap (also Meldable
Heap Heap or HEAP may refer to: Computing and mathematics * Heap (data structure), a data structure commonly used to implement a priority queue * Heap (mathematics), a generalization of a group * Heap (programming) (or free store), an area of memory f ...
or Randomized Meldable
Priority Queue In computer science, a priority queue is an abstract data-type similar to a regular queue or stack data structure in which each element additionally has a ''priority'' associated with it. In a priority queue, an element with high priority is se ...
) is a priority queue based
data structure In computer science, a data structure is a data organization, management, and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the rel ...
in which the underlying structure is also a heap-ordered
binary tree In computer science, a binary tree is a k-ary k = 2 tree data structure in which each node has at most two children, which are referred to as the ' and the '. A recursive definition using just set theory notions is that a (non-empty) binar ...
. However, there are no restrictions on the shape of the underlying binary tree. This approach has a number of advantages over similar data structures. It offers greater simplicity: all operations for the randomized meldable heap are easy to implement and the constant factors in their complexity bounds are small. There is also no need to preserve balance conditions and no satellite information within the nodes is necessary. Lastly, this structure has good worst-case time efficiency. The execution time of each individual operation is at most logarithmic with high probability.A. Gambin and A. Malinowski. 1998. Randomized Meldable Priority Queues. In Proceedings of the 25th Conference on Current Trends in Theory and Practice of Informatics: Theory and Practice of Informatics (SOFSEM '98), Branislav Rovan (Ed.). Springer-Verlag, London, UK, UK, 344-349.


Operations

The randomized meldable heap supports a number of common operations. These are insertion, deletion, and a searching operation, findMin. The insertion and deletion operations are implemented in terms of an additional operation specific to the meldable heap, Meld(Q1, Q2).


Meld

The basic goal of the meld (also called merge) operation is to take two heaps (by taking each heaps root nodes), Q1 and Q2, and merges them, returning a single heap node as a result. This heap node is the root node of a heap containing all elements from the two subtrees rooted at Q1 and Q2. A nice feature of this meld operation is that it can be defined recursively. If either heaps are null, then the merge is taking place with an empty set and the method simply returns the root node of the non-empty heap. If both Q1 and Q2 are not nil, check if Q1 > Q2. If it is, swap the two. It is therefore ensured that Q1 < Q2 and that the root node of the merged heap will contain Q1. We then recursively merge Q2 with Q1.left or Q1.right. This step is where the randomization comes in as this decision of which side to merge with is determined by a coin toss. function Meld(Node ''Q''1, Node ''Q''2) if ''Q''1 is nil => return ''Q''2 if ''Q''2 is nil => return ''Q''1 if ''Q1'' > ''Q''2 => swap ''Q''1 and ''Q''2 if coin_toss is 0 => ''Q''1.''left'' = Meld(''Q''1.''left'', ''Q''2) else ''Q''1.''right'' = Meld(''Q''1.''right'', ''Q''2) return ''Q''1


Insert

With the meld operation complete, inserting into the meldable heap is easy. First, a new node, u, is created containing the value x. This new node is then simply melded with the heaps root node. function Insert(x) Node u = new Node u.x = x root = Meld(u, root) root.parent = nil increment node count


Remove

Similarly easy to the insert operation, Remove() uses the Meld operation to eliminate the root node from the heap. This is done by simply melding the two children of the root node and making the returned node the new root. function Remove() root = Meld(root.left, root.right) if root is not nil => root.parent = nil decrement node count


FindMin

Possibly the easiest operation for the randomized meldable heap, FindMin() simply returns the element currently stored in the heap's root node.


Additional operations

Some additional operations that can be implemented for the meldable heap that also have ''O''(log''n'') worst-case efficiency are: * Remove(u) - Remove the node u and its key from the heap. * Absorb(Q) - Add all elements of the meldable heap Q to this heap, emptying Q in the process. * DecreaseKey(u, y) - Decreases the key in node u to y (pre-condition: y <= u.x).


Efficiency analysis

As all non-constant-time operations are defined in terms of the Meld operation, the efficiency of these operations can be determined through analysis of the complexity of melding two randomized heaps. The result of this analysis is that the expected time of any meldable priority queue operation on a n-node randomized heap is ''O''(log''n''). P. Morin

Open Data Structures, p. 191-


History

The meldable heap appears to have first been proposed in 1998 by Gambin and Malinowski.


Variants

While the randomized meldable heap is the simplest form of a meldable heap implementation, others do exist. These are: *
Leftist heap In computer science, a leftist tree or leftist heap is a priority queue implemented with a variant of a binary heap. Every node x has an ''s-value'' which is the distance to the nearest leaf in subtree rooted at x. In contrast to a ''binary heap'' ...
*
Binomial heap In computer science, a binomial heap is a data structure that acts as a priority queue but also allows pairs of heaps to be merged. It is important as an implementation of the mergeable heap abstract data type (also called meldable heap), which ...
*
Fibonacci Heap 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 bina ...
*
Pairing heap 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 h ...
*
Skew heap A skew heap (or self-adjusting heap) is a heap data structure implemented as a binary tree. Skew heaps are advantageous because of their ability to merge more quickly than binary heaps. In contrast with binary heaps, there are no structural constrai ...


References

{{reflist Priority queues