Misplaced Pages

2–3 heap

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
This article may be too technical for most readers to understand. Please help improve it to make it understandable to non-experts, without removing the technical details. (April 2024) (Learn how and when to remove this message)
This article relies largely or entirely on a single source. Relevant discussion may be found on the talk page. Please help improve this article by introducing citations to additional sources.
Find sources: "2–3 heap" – news · newspapers · books · scholar · JSTOR (May 2024)

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

An r-ary polynomial of trees is defined as P = a k 1 r k 1 + + a 1 r + a 0 {\displaystyle P=\mathbf {a} _{k-1}\mathbf {r} ^{k-1}+\dots +\mathbf {a} _{1}\mathbf {r} +\mathbf {a} _{0}} where 0 a i r 1 {\displaystyle 0\leq a_{i}\leq r-1} . This polynomial notation for trees of n {\displaystyle n} nodes is unique. The tree a i r i {\displaystyle \mathbf {a} _{i}\mathbf {r} ^{i}} is actually a i {\displaystyle a_{i}} copy of r i {\displaystyle \mathbf {r} ^{i}} that their roots are connected with a i 1 {\displaystyle a_{i}-1} edges sequentially and the path of these a i 1 {\displaystyle a_{i}-1} edge is called the main trunk of the tree a i r i {\displaystyle \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 a i r i {\displaystyle \mathbf {a} _{i}\mathbf {r} ^{i}} and a i r i {\displaystyle \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 r {\displaystyle a_{i}+a'_{i}\geq r} we will have a term of form ( a i + a i r ) r i {\displaystyle (\mathbf {a} _{i}+\mathbf {a} '_{i}-\mathbf {r} )\mathbf {r} ^{i}} and a carry tree r i + 1 {\displaystyle \mathbf {r} ^{i+1}} . Otherwise, we would have only a tree ( a i + a i ) r i {\displaystyle (\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 {\displaystyle 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 ) {\displaystyle 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 {\displaystyle T} , then we delete the minimum from T {\displaystyle T} and we add the resulting polynomial queue Q {\displaystyle Q} to P T {\displaystyle P-T} in total time O ( r log r n ) {\displaystyle O(r\log _{r}{n})} .

(2,3)-heap

Source:

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

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

Operations on (2,3)-heap

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

Decrease Key: To be done!

References

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