Heap (data structure)
From Wikipedia, the free encyclopedia
Categories: All articles with unsourced statements | Articles with unsourced statements since November 2007 | Heaps (structure)
|
This article is about heap data structures. For “the heap” as a large pool of unused memory, see Dynamic memory allocation.
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if B is a child node of A, then key(A) ≥ key(B). This implies that an element with the greatest key is always in the root node, and so 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 heapsort.
Variants
Comparison of theoretic bounds for variantsThe following complexities[1] are worst-case for binary and binomial heaps and amortized complexity for Fibonacci heap. O(f) gives asymptotic upper bound and Θ(f) is asymptotically tight bound (see Big O notation). Function names assume a min-heap.
For pairing heaps the insert and merge operations are conjectured[citation needed] to be O(1) amortized complexity but this has not yet been proven. decreaseKey is not O(1) amortized complexity [1] [2] Heap applicationsHeaps are favorite data structures for many applications.
Interestingly, binary heaps may be represented using an array alone. The first (or last) element will contain the root. The next two elements of the array contain its children. The next four contain the four children of the two child nodes, etc. Thus the children of the node at position One more advantage of heaps over trees in some applications is that construction of heaps can be done in linear time using Tarjan's algorithm. Heap implementations
See alsoNotes
External links
de:Heap (Datenstruktur) es:Montículo (programación) fr:Tas (informatique) ko:힙 (자료 구조) is:Hrúga (tölvunarfræði) it:Heap he:ערימה (מבנה נתונים) lt:Krūva nl:Heap ja:ヒープ no:Heap pl:Kopiec (informatyka) pt:Heap ru:Сортирующее дерево sk:Halda sl:Kopica fi:Keko (tietorakenne) sv:Heap (datastruktur) uk:Купа (структура даних) |


