2–3 heap

From HandWiki

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 [math]\displaystyle{ O(\log(n)) }[/math] amortized time.
  • Decrease-key takes constant amortized time.
  • Insertion takes constant amortized time.

Polynomial of trees

Source:[1]

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

An r-ary polynomial of trees is defined as [math]\displaystyle{ P = \mathbf{a}_{k-1}\mathbf{r}^{k-1} + \dots + \mathbf{a}_1\mathbf{r} + \mathbf{a}_0 }[/math] where [math]\displaystyle{ 0 \leq a_i \leq r-1 }[/math]. This polynomial notation for trees of [math]\displaystyle{ n }[/math] nodes is unique. The tree [math]\displaystyle{ \mathbf{a}_i\mathbf{r}^i }[/math] is actually [math]\displaystyle{ a_i }[/math] copy of [math]\displaystyle{ \mathbf{r}^i }[/math] that their roots are connected with [math]\displaystyle{ a_i-1 }[/math] edges sequentially and the path of these [math]\displaystyle{ a_i-1 }[/math] edge is called the main trunk of the tree [math]\displaystyle{ \mathbf{a}_i\mathbf{r}^i }[/math]. 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 [math]\displaystyle{ \mathbf{a}_i \mathbf{r}^i }[/math] and [math]\displaystyle{ \mathbf{a}'_i \mathbf{r}^i }[/math], we just reorder the trees in the main trunk based on the keys in the root of trees. If [math]\displaystyle{ a_i + a'_i \geq r }[/math] we will have a term of form [math]\displaystyle{ (\mathbf{a}_i+\mathbf{a}'_i-\mathbf{r}) \mathbf{r}^i }[/math] and a carry tree [math]\displaystyle{ \mathbf{r}^{i+1} }[/math]. Otherwise, we would have only a tree [math]\displaystyle{ (\mathbf{a}_i+\mathbf{a}'_i) \mathbf{r}^i }[/math]. So the sum of two r-nomial queues are actually similar to the addition of two number in base [math]\displaystyle{ r }[/math].

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 [math]\displaystyle{ O(r \log_r{n}) }[/math] time.

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

(2,3)-heap

Source:[1]

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

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

Operations on (2,3)-heap

Delete-min: First find the minimum by scanning the root of the trees. Let [math]\displaystyle{ T(i) }[/math] be the tree containing minimum element and let [math]\displaystyle{ Q }[/math] be the result of removing root from [math]\displaystyle{ T(i) }[/math]. Then merge [math]\displaystyle{ P - T(i) }[/math] and [math]\displaystyle{ Q }[/math] (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, [math]\displaystyle{ T(0) }[/math] labeled with this key.

Decrease Key: To be done!

References

  1. 1.0 1.1 Takaoka, Tadao (March 2003). "Theory of 2–3 Heaps" (in en). Discrete Applied Mathematics 126 (1): 115–128. doi:10.1016/S0166-218X(02)00219-6. https://linkinghub.elsevier.com/retrieve/pii/S0166218X02002196.