data-structures - 为什么二叉堆一定是完全二叉树?

标签 data-structures heap

堆属性说:

If A is a parent node of B then the key of node A is ordered with respect to the key of node B with the same ordering applying across the heap. Either the keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node (this kind of heap is called max heap) or the keys of parent nodes are less than or equal to those of the children and the lowest key is in the root node (min heap).



但为什么在这个wiki ,二叉堆必须是 完整 二叉树?在我的印象中,堆属性并不意味着这一点。

最佳答案

根据wikipedia article您提供的,二叉堆必须符合堆属性(如您所讨论的)和形状属性(要求它是一个完整的二叉树)。如果没有 shape 属性,就会失去数据结构提供的运行时优势(即完整性确保在删除元素时有一种定义明确的方法来确定新的根,等等)

关于data-structures - 为什么二叉堆一定是完全二叉树?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25319305/

相关文章:

java - split 二叉树

java - 如何将类的一个参数的值复制到另一个Collection对象?

java - Prim算法实现错误,Empty Heap

java - Java 中的优先级队列(最小堆)排序

data-structures - 设计一个数据结构来保存大量数据

C 结构和 malloc 函数

java - 使用数组的 O(1) 插入时间的优先级队列?

java - native 库中减少键/增加键支持

javascript - 使用堆的优先级队列 - JavaScript 和 C++ 实现之间的区别

c++ - 如何在 C++ 中处理堆