Jump to content

2–3 heap

From Wikipedia, the free encyclopedia

In computer science, a 2–3 heap is a data structure, a variation on the heap, designed by Tadao Takaoka in 1999. The structure is similar to the Fibonacci heap, and borrows from the 2–3 tree.

Time costs for some common heap operations are:

  • Delete-min takes amortized time.
  • Decrease-key takes constant amortized time.
  • Insertion takes constant amortized time.

Polynomial of trees

[edit]

Source:[1]

A linear tree of size is a sequential path of nodes with the first node as a root of the tree and it is represented by a bold (e.g. is a linear tree of a single node). Product of two trees and , is a new tree with every node of is replaced by a copy of and for each edge of we connect the roots of the trees corresponding to the endpoints of the edge. Note that this definition of product is associative but not commutative. Sum of two trees and is the collection of two trees and .

Consider the operation on trees such that . The tree is produced by linking the root of the tree as a child of the root of tree . Now consider the linear tree . We define in the following way:

The path created from this linking forms the th trunk of which can also be called the th dimension of the tree.

An r-ary polynomial of trees is defined as where . This polynomial notation for trees of nodes is unique. The tree is an copy of such that their roots are connected with edges sequentially. The path of these edges is called the main trunk of the tree . Furthermore, an r-ary polynomial of trees is called an r-nomial queue if nodes of the polynomial of trees are associated with keys in heap property.

A polynomial heap, in fact a (2,3) heap with a dimension representation of its trees

Operations on r-nomial queues

[edit]

To merge two terms of form and , we just reorder the trees in the main trunk based on the keys in the root of trees. If we will have a term of form and a carry tree . Otherwise, we would have only a tree . So the sum of two r-nomial queues are actually similar to the addition of two number in base .

An insertion of a key into a polynomial queue is like merging a single node with the label of the key into the existing r-nomial queue, taking time.

To delete the minimum, first, we need to find the minimum in the root of a tree, say , then we delete the minimum from and we add the resulting polynomial queue to in total time .

(2,3)-heap

[edit]

Source:[1]

An tree is defined recursively by

The root of the tree has degree , and can be formed by different trees of degree . The root of is called the head node of the th trunk. The dimension of non-head nodes on the trunk is , while the dimension of the head node is or larger, depending on whether it gets linked again. The tree of type on the th trunk of rooted at a node is called .

Informally, a tree of dimension is formed by linking roots of 2 or 3 trees of dimension in a line.

An extended polynomial of trees, , is defined by . If we assign keys into the nodes of an extended polynomial of trees in heap order it is called an , and the special case of and is a .

An example of a 2-3 heap, where P = 2T(3) + 1T(2) + 1T(0)

Workspace of a Node The workspace of a node is the local neighborhood, defined for nodes not on the main trunks of trees in the heap. Assume the dimension of is , so that it is on an th trunk. The workspace of then consists of all the nodes on the th trunk, the th trunk, and those on other th trunks whose head nodes are on the th trunk. The workspace is then a collection of nodes between size 4 to 9. The head node of the workspace is the node on the first position of the th trunk.

Operations on (2,3)-heap

[edit]

Delete-min: First find the minimum by scanning the root of the trees. Let be the tree containing minimum element and let be the result of removing root from . Then merge and (The merge operation is similar to merge of two r-nomial queues).

Insertion: In order to insert a new key, merge the currently existing (2,3)-heap with a single node tree, labeled with this key.

Removal of a Tree: Trees rooted at the top most trunks of the heap are not removed. If we want to remove the tree of type of a node , we need to consider two cases, one where the workspace of is of size 4, and another where the size is larger. Note that is a node on an th trunk of the heap.

In a workspace of size larger than 4, the th trunk either has 2 nodes or 3 nodes. If it has 3 nodes, then it can be of the form or . In either case, we can remove and shrink the trunk. Note that cannot be the first node on the th trunk since that node would be on the th trunk, which must exist as nodes on the top most trunks are not removed.

If the th trunk is of the form , then remove and account for the loss of the th trunk by moving around some other trees of type in the workspace.

For the case in which the workspace is of size 4, remove and rearrange the other three nodes so that two come under the head node of the workspace. This makes an th trunk of length two (three nodes in a line) but causes a loss of an th trunk. This loss is fixed by moving around trees from workspace of nodes on the th dimension. This process continues upwards in dimension until it is resolved.

Decrease Key: Assume the key of node of dimension is decreased, and it is not at the top level. Then is removed and inserted into the th term at the top level of the heap (i.e. in our extended polynomial), where . If was at the top level of its tree, then the heap property was not violated from decrease key so no tree removal is required. However, the trunks on the top most trunk may need to be rearranged.

References

[edit]
  1. ^ a b Takaoka, Tadao (March 2003). "Theory of 2–3 Heaps". Discrete Applied Mathematics. 126 (1): 115–128. doi:10.1016/S0166-218X(02)00219-6.