In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, a 2–3 heap is a
data structure
In computer science, a data structure is a data organization, management, and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the rel ...
, a variation on the
heap
Heap or HEAP may refer to:
Computing and mathematics
* Heap (data structure), a data structure commonly used to implement a priority queue
* Heap (mathematics), a generalization of a group
* Heap (programming) (or free store), an area of memory f ...
, designed by
Tadao Takaoka
Tadao (written: 忠雄, 忠夫, 忠男, 忠生, 忠郎 or 理男) is a masculine Japanese given name. Notable people with the name include:
*, Japanese architect
*, Japanese ''daimyō''
*Tadao Baba (born 1944), Japanese motorcycle engineer
*, Jap ...
in 1999. The structure is similar to the
Fibonacci heap
In computer science, a Fibonacci heap is a data structure for priority queue operations, consisting of a collection of heap-ordered trees. It has a better amortized running time than many other priority queue data structures including the bina ...
, and borrows from the
2–3 tree.
Time costs for some common heap operations are:
* ''Delete-min'' takes
amortized time
In computer science, amortized analysis is a method for analyzing a given algorithm's complexity, or how much of a resource, especially time or memory, it takes to execute. The motivation for amortized analysis is that looking at the worst-case ...
.
* ''Decrease-key'' takes constant amortized time.
* ''Insertion'' takes constant amortized time.
Polynomial of trees
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
.
An r-ary polynomial of trees is defined as
where
. This polynomial notation for trees of
nodes is unique. The tree
is actually
copy of
that their roots are connected with
edges sequentially and the path of these
edge 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.
Operations on r-nomial queues
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
An
tree
is defined recursively by
for
(
is between
and
and
operations are evaluated from right to left) where for two trees,
and
, the result of the operation
is connecting the root of
as a rightmost child to the root of
and
is a single node tree. Note that the root of the tree
has degree
.
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
, and the special case of
and
is called
.
Operations on (2,3)-heap
Delete-min: First of all, we 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 we merge
and
(The merge operation is similar to merge of two r-nomial queues).
Insertion: In order to insert a new key, we merge the currently existing (2,3)-heap with a single node tree,
labeled with this key.
Decrease Key: To be done!
References
Heaps (data structures)
{{datastructure-stub