Heap 练习题

来源:互联网 发布:linux系统界面 编辑:程序博客网 时间:2024/06/05 07:29

Basic
find-max or find-min: find the maximum item of a max-heap or a minimum item of a min-heap (a.k.a. peek)

insert: adding a new key to the heap (a.k.a., push[1])

extract-min [or extract-max]: returns the node of minimum value from a min heap [or maximum value from a max heap] after removing it from the heap (a.k.a., pop[2])

delete-max or delete-min: removing the root node of a max- or min-heap, respectively

replace: pop root and push a new key. More efficient than pop followed by push, since only need to balance once, not twice, and appropriate for fixed-size heaps.[3]

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 – an optimized form of size when total size is not needed.

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.

0 0
原创粉丝点击