Binary heap: Difference between revisions

Content deleted Content added
eliminate multiple "garden-path" readings (grammatical flow ambiguities)
1.) The point is fundamentally important enough to the topic to warrant a list. 2.) Fix scope ambiguity (narrow vs. wide) of the word "respectively" 3.) Use of existing MOS:COLON remains correct, now covered by a different sub-guideline
Line 26:
 
A binary heap is defined as a binary tree with two additional constraints:<ref>{{citation | author=Y Narahari | title=Data Structures and Algorithms | chapter=Binary Heaps | url=https://gtl.csa.iisc.ac.in/dsa/ | chapter-url=http://lcm.csa.iisc.ernet.in/dsa/node137.html}}</ref>
 
*Shape property: a binary heap is a ''[[complete binary tree]]''; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
*Heap property: the key stored in each node is either greater than or equal to (≥) or less than or equal to (≤) the keys in the node's children, according to some [[total order]].
 
Heaps where the parent key is greater than or equal to (≥) the child keys are called ''max-heaps''; those where it is less than or equal to (≤) are called ''min-heaps''. Efficient (that is, [[logarithmic time]]) algorithms are known for the two operations needed to implement a priority queue on a binary heap: inserting
*Inserting an element, and removing;
*Removing the smallest or largest element from (respectively) a min-heap or max-heap, respectively.
Binary heaps are also commonly employed in the [[heapsort]] [[sorting algorithm]], which is an in-place algorithm because binary heaps can be implemented as an [[implicit data structure]], storing keys in an array and using their relative positions within that array to represent child–parent relationships.
 
==Heap operations==