Content deleted Content added
m More clear to say "a branches for each node" than "for each node a branches" |
|||
Line 6:
The heap is one maximally efficient implementation of an [[abstract data type]] called a [[priority queue]], and in fact, priority queues are often referred to as "heaps", regardless of how they may be implemented. In a heap, the highest (or lowest) priority element is always stored at the root. However, a heap is not a sorted structure; it can be regarded as being partially ordered. A heap is a useful data structure when it is necessary to repeatedly remove the object with the highest (or lowest) priority, or when insertions need to be interspersed with removals of the root node.
A common implementation of a heap is the [[binary heap]], in which the tree is a [[binary tree]] (see figure). The heap data structure, specifically the binary heap, was introduced by [[J. W. J. Williams]] in 1964, as a data structure for the [[heapsort]] sorting algorithm.<ref>{{Citation |first=J. W. J. |last=Williams |author-link=J. W. J. Williams |title=Algorithm 232 - Heapsort |year=1964 |journal=[[Communications of the ACM]] |volume=7 |issue=6 |pages=347–348 |doi= 10.1145/512274.512284}}</ref> Heaps are also crucial in several efficient [[graph algorithms]] such as [[Dijkstra's algorithm]]. When a heap is a complete binary tree, it has a smallest possible height—a heap with ''N'' nodes and
Note that, as shown in the graphic, there is no implied ordering between siblings or cousins and no implied sequence for an [[Inorder traversal|in-order traversal]] (as there would be in, e.g., a [[binary search tree]]). The heap relation mentioned above applies only between nodes and their parents, grandparents, etc. The maximum number of children each node can have depends on the type of heap.
|