← [ BACK_TO_NOTES ]

Heap Interview Problems

比较合并有序链表、线段重叠与数组减半如何用堆维护当前候选,并区分各自的更新规则。

#algorithm #synthesis #growing #heap

[!info] related notes 算法面试题型 MOC

Heap Interview Problems

Merge k Sorted Lists

  • Use a min-heap keyed by node value.
  • Initialize heap with each list head.
  • Pop smallest, append to result, then push its next.
  • Reference: 合并K个有序链表

Maximum Overlapping Segments

  • Sort segments by start.
  • Use a min-heap of end points.
  • For each segment:
    • For non-empty half-open intervals [start, end), pop ends <= start; touching endpoints do not overlap.
    • Push current end.
    • Heap size is overlap count at this point; track max.
  • Reference: 线段最多重合问题

Min Operations to Halve Array Sum

  • Use a max-heap.
  • Repeatedly take current max, halve it, put back, accumulate reduction until reached half of total sum.
  • Reference: 数组和减半最少操作

各题的堆不变量

题型堆中保存什么为什么可以取堆顶
合并有序链表每条未耗尽链表的当前头节点每条链表内部已非递减,全局最小必在这些头中
半开区间重叠已开始且未结束的区间终点最早结束的区间最先失活,堆大小表示当前数量
数组减半每个数当前的值当前值最大者本次减少量也最大,修改后需重新入堆

堆只负责取极值,排序前提、端点约定和贪心正确性仍由具体问题决定。

创建于 2026/3/16 更新于 2026/10/7
Digital Biome
Access

键盘导航

j / k / ↑ / ↓
选择对象
Enter / o
打开选择
/ 或 Ctrl+K
全站搜索
i / f / 1–4
筛选当前列表
g → h / l / p / t / a
首页 / 笔记 / 项目 / 工具 / About
r → 1–9
打开所选对象的关联
u
返回上一页
Esc
关闭浮层 / 取消命令;输入框内清空文本