In computer science, a heap is a specialized tree-based data structure that satisfies the heap property. Its base datatype (used for node keys) must be an ordered set.
If B is a child node of A, then the heap property is that:
This implies that the greatest element is always in the root node, and such a heap is sometimes called a max heap. (Alternatively, if the comparison is reversed, the smallest element is always in the root node, which results in a min heap.) This is why heaps are used to implement priority queues. The efficiency of heap operations is crucial in several graph algorithms.
The operations commonly performed with a heap are
Heaps are used in the sorting algorithm called heapsort.
Function names assume a min-heap:
| Operation | Binary | Binomial | Fibonacci | Pairing | Leftist | Soft | 2-3 | Treap | Beap | ||
|---|---|---|---|---|---|---|---|---|---|---|---|
| worst-case | worst-case | amortized | worst-case | amortized | worst-case | worst-case | |||||
| find-min | O | O | O | O | O | O | O | ||||
| delete-min | O | O | O | O | O | O | O | ||||
| insert | O | O | O | O | O or O | O | O | ||||
| decrease-key | O | O | O | O | O or O | O | O | ||||
| merge | O | O | O | O | O or O | O | O | ||||
For pairing heaps the insert, decreaseKey and merge operations are conjectured to be O amortized complexity but this has not yet been proven.
One more advantage of heap over tree in some applications is construction of heap can be done in linear time using Tarjan's algorithm.
Data structures | Trees (structure)
Heap (Datenstruktur) | Montículo (programación) | Tas | Hrúga (tölvunarfræði) | Heap | ערימה (מבנה נתונים) | Krūva | Heap | ヒープ | Kopiec (informatyka) | Kopica | Heap (datastruktur) | Купа (структура даних) | 堆
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Heap (data structure)".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world