Min-max heap
Computer data structure / From Wikipedia, the free encyclopedia
Dear Wikiwand AI, let's keep it short by simply answering these key questions:
Can you list the top facts and stats about Min-max heap?
Summarize this article for a 10 year old
In computer science, a min-max heap is a complete binary tree data structure which combines the usefulness of both a min-heap and a max-heap, that is, it provides constant time retrieval and logarithmic time removal of both the minimum and maximum elements in it.[2] This makes the min-max heap a very useful data structure to implement a double-ended priority queue. Like binary min-heaps and max-heaps, min-max heaps support logarithmic insertion and deletion and can be built in linear time.[3] Min-max heaps are often represented implicitly in an array;[4] hence it's referred to as an implicit data structure.
Min-max heap | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Type | binary tree/heap | |||||||||||||||||
Invented | 1986 | |||||||||||||||||
|
The min-max heap property is: each node at an even level in the tree is less than all of its descendants, while each node at an odd level in the tree is greater than all of its descendants.[4]
The structure can also be generalized to support other order-statistics operations efficiently, such as find-median
, delete-median
,[2]find(k)
(determine the kth smallest value in the structure) and the operation delete(k)
(delete the kth smallest value in the structure), for any fixed value (or set of values) of k. These last two operations can be implemented in constant and logarithmic time, respectively. The notion of min-max ordering can be extended to other structures based on the max- or min-ordering, such as leftist trees, generating a new (and more powerful) class of data structures.[4] A min-max heap can also be useful when implementing an external quicksort.[5]