Weak heap

Weak heaps require the ability to exchange the left and right children (and associated subtrees) of a node.

A weak heap is thus not a strictly implicit data structure since it requires O(n) additional space (⁠1/2⁠ bit per node).

However, it is often possible to find space for this extra bit within the node structure, such as by tagging a pointer which is already present.

Viewed as a multi-way tree, each node in a weak heap is linked to two others: a "next sibling" and a "first child".

If the node is the left child (next sibling), its distinguished ancestor is the same as its binary parent's.

In the implicit tree, finding the binary parent is easy, but its reverse bit must be consulted to determine which type of child the node is.

This operation can be performed on the implicit tree structure because the heaps being merged are never arbitrary.

After comparing the two roots, the merge proceeds in one of two ways: The second case works because, in the multi-way tree, each node keeps its children with it.

Weak heaps may be used to sort an array, in essentially the same way as a conventional heapsort.

It can be done on various orders, but a simple bottom-up implementation works from the end of the array to the beginning, merging each node with its distinguished ancestor.

As with binary heaps, weak heaps can support the typical operations of a priority queue data structure: insert, delete-min, delete, or decrease-key, in logarithmic time per operation.

The new node is added at the leaf level, then compared with its distinguished ancestor and swapped if necessary (the merge operation).

[3][5] They were later investigated as a more generally applicable priority queue data structure.