Heap 练习题

本文详细介绍了堆(Heap)的操作,包括查找最大值/最小值、插入元素、删除最大值/最小值、替换节点等基本操作。此外,还探讨了创建堆、合并堆以及调整节点位置的方法,如增加/减少关键字、删除节点以及上滤/下滤过程。这些操作是理解和应用堆数据结构的关键。
摘要由CSDN通过智能技术生成

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值