algorithm - d-堆删除算法

标签 algorithm

Binary heaps are so simple that they are almost always used when priority queues are needed. A simple generalization is a d-heap, which is exactly like a binary heap except that all nodes have d children (thus, a binary heap is a 2-heap).

Notice that a d-heap is much more shallow than a binary heap, improving the running time of inserts to O(log( base(d)n)). However, the delete_min operation is more expensive, because even though the tree is shallower, the minimum of d children must be found, which takes d - 1 comparisons using a standard algorithm. This raises the time for this operation to O(d logdn). If d is a constant, both running times are, of course, O(log n).

我的问题是对于 d 个 child ,我们应该进行 d 次比较,作者如何使用标准算法得出 d-1 次比较的结论。

谢谢!

最佳答案

你比 child 少了一个比较。

例如两个 child a1a2您只比较一次 a1<=>a2找到较小的那个。

三个 child a1 , a2 , a3您比较一次以找到 a1 中较小的一个和a2第二次将较小的与 a3 进行比较.

通过归纳,您会发现对于每个额外的子项,您都需要进行额外的比较,将先前列表的最小值与新添加的子项进行比较。

因此,一般来说 d您需要的 child d-1比较以找到最小值。

关于algorithm - d-堆删除算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7469595/

相关文章:

algorithm - 在一组不断变化的线段中进行最近邻搜索

algorithm - 用于在图中查找最小切割的随机收缩算法

algorithm - 3-SAT 的 "input size"是什么意思?

arrays - 字符串数组所有排列的最长运行序列

python - 什么是数据转储的最佳压缩算法

algorithm - 如何计算大小为 n*m 的网格中有多少个不同大小的正方形?

algorithm - 如何选择列表中乱序的所有元素?

algorithm - 确定球体是否与物体相交

algorithm - 字符串格式化算法建议

c++ - 移动 Physics 对象以进行穿透的最小尺寸 Vec3 = 0