heap - Do I have to make the possibilities of position of 4th minimum?
问题描述
A Min heap was constructed and the place of second minimum is at the right child of the root. You are asked to mark all possible places of the fourth minimum, assuming that duplicates don’t exists in the data structure.
解决方案
如果最小堆中没有重复,则每个节点的父节点都小于子节点。
每个节点可以有任何值,但不能与另一个相同。为了使图表更容易,只需使用整数。
[1]
[A] [2]
[B] [C] [D] [E]
- D 和 E 未排序。
- D 大于 2。
- E 大于 2。
- A 大于 1 但不大于 2。
因此,A、B、C、D 或 E 中的任何一个都可能是 4。
推荐阅读
- java - 从 ant 迁移到 gradle - macrodef 替代方案?
- azure-devops - 如何为 VSTS 构建代理提供完整的 CPU 能力?
- angular - Primeng p-datatable 列宽、最大宽度或最小宽度不起作用
- python-3.x - 如何在 CSV 文件中设置/写入列表项值?
- node.js - 将图像从节点上传到 Cloudinary
- css - scss 文件将占位符文本设置为粗体
- ios - 自定义静态表格视图标题 - Swift
- ruby-on-rails - ActiveRecord::RecordNotFound rspec 如何测试
- python - 将 python 字节数组解析为 golang []byte
- python - 将 dict 转换为每个组合的 dict 列表