Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Heap (data structure)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Operations== The common operations involving heaps are: ;Basic * ''find-max'' (or ''find-min''): find a maximum item of a max-heap, or a minimum item of a min-heap, respectively (a.k.a. ''[[Peek (data type operation)|peek]]'') * ''insert'': adding a new key to the heap (a.k.a., ''push''<ref>The Python Standard Library, 8.4. heapq β Heap queue algorithm, [https://docs.python.org/3/library/heapq.html#heapq.heappush heapq.heappush]</ref>) * ''extract-max'' (or ''extract-min''): returns the node of maximum value from a max heap [or minimum value from a min heap] after removing it from the heap (a.k.a., ''pop''<ref>The Python Standard Library, 8.4. heapq β Heap queue algorithm, [https://docs.python.org/3/library/heapq.html#heapq.heappop heapq.heappop]</ref>) * ''delete-max'' (or ''delete-min''): removing the root node of a max heap (or min heap), respectively * ''replace'': pop root and push a new key. This is more efficient than a pop followed by a push, since it only needs to balance once, not twice, and is appropriate for fixed-size heaps.<ref>The Python Standard Library, 8.4. heapq β Heap queue algorithm, [https://docs.python.org/3/library/heapq.html#heapq.heapreplace heapq.heapreplace]</ref> ;Creation * ''create-heap'': create an empty heap * ''heapify'': create a heap out of given array of elements * ''merge'' (''union''): joining two heaps to form a valid new heap containing all the elements of both, preserving the original heaps. * ''meld'': joining two heaps to form a valid new heap containing all the elements of both, destroying the original heaps. ;Inspection * ''size'': return the number of items in the heap. * ''is-empty'': return true if the heap is empty, false otherwise. ;Internal * ''increase-key'' or ''decrease-key'': updating a key within a max- or min-heap, respectively * ''delete'': delete an arbitrary node (followed by moving last node and sifting to maintain heap) * ''sift-up'': move a node up in the tree, as long as needed; used to restore heap condition after insertion. Called "sift" because node moves up the tree until it reaches the correct level, as in a [[sieve]]. * ''sift-down'': move a node down in the tree, similar to sift-up; used to restore heap condition after deletion or replacement.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)