2–3 heap

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 $$O(\log(n))$$ amortized time.
 * Decrease-key takes constant amortized time.
 * Insertion takes constant amortized time.

Polynomial of trees
Source:

A linear tree of size $$r$$ is a sequential path of $$r$$ nodes with the first node as a root of the tree and it is represented by a bold $$\mathbf{r}$$ (e.g. $$\mathbf{1}$$ is a linear tree of a single node). Product $$P = ST$$ of two trees $$S$$ and $$T$$, is a new tree with every node of $$S$$ is replaced by a copy of $$T$$ and for each edge of $$S$$ 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 $$S+T$$ of two trees $$S$$ and $$T$$ is the collection of two trees $$S$$ and $$T$$.

An r-ary polynomial of trees is defined as $$P = \mathbf{a}_{k-1}\mathbf{r}^{k-1} + \dots + \mathbf{a}_1\mathbf{r} + \mathbf{a}_0$$ where $$0 \leq a_i \leq r-1$$. This polynomial notation for trees of $$n$$ nodes is unique. The tree $$\mathbf{a}_i\mathbf{r}^i$$ is actually $$a_i$$ copy of $$\mathbf{r}^i$$ that their roots are connected with $$a_i-1$$ edges sequentially and the path of these $$a_i-1$$ edge is called the main trunk of the tree $$\mathbf{a}_i\mathbf{r}^i$$. 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.

Operations on r-nomial queues
To merge two terms of form $$\mathbf{a}_i \mathbf{r}^i$$ and $$\mathbf{a}'_i \mathbf{r}^i$$, we just reorder the trees in the main trunk based on the keys in the root of trees. If $$a_i + a'_i \geq r$$ we will have a term of form $$(\mathbf{a}_i+\mathbf{a}'_i-\mathbf{r}) \mathbf{r}^i$$ and a carry tree $$\mathbf{r}^{i+1}$$. Otherwise, we would have only a tree $$(\mathbf{a}_i+\mathbf{a}'_i) \mathbf{r}^i$$. So the sum of two r-nomial queues are actually similar to the addition of two number in base $$r$$.

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 $$O(r \log_r{n})$$ time.

To delete the minimum, first, we need to find the minimum in the root of a tree, say $$T$$, then we delete the minimum from $$T$$ and we add the resulting polynomial queue $$Q$$ to $$P-T$$ in total time $$O(r \log_r{n})$$.

(2,3)-heap
Source:

An $$(l,r)-$$ tree $$T(i)$$ is defined recursively by $$T(i) = T_1(i-1) \triangleleft \dots \triangleleft T_s(i-1)$$ for $$i \geq 1$$ ($$s$$ is between $$l$$ and $$r$$ and $$(s-1)$$ $$\triangleleft$$ operations are evaluated from right to left) where for two trees, $$A$$ and $$B$$, the result of the operation$$ A \triangleleft B $$ is connecting the root of $$ B $$ as a rightmost child to the root of $$A$$ and $$T(0) $$ is a single node tree. Note that the root of the tree $$T(i)$$ has degree $$i$$.

An extended polynomial of trees, $$P$$, is defined by $$P = a_{k-1}T(k-1) + \dots + a_1T(1) + a_0$$. If we assign keys into the nodes of an extended polynomial of trees in heap order it is called $$(l, r)-heap$$, and the special case of $$l = 2$$ and $$r = 3$$ is called $$(2, 3)-heap$$.

Operations on (2,3)-heap
Delete-min: First find the minimum by scanning the root of the trees. Let $$T(i)$$ be the tree containing minimum element and let $$Q$$ be the result of removing root from $$T(i)$$. Then merge $$P - T(i)$$ and $$Q$$ (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, $$T(0)$$ labeled with this key.

Decrease Key: To be done!