知识卡片
成对比较同时求极值
同时求最小值和最大值时,每两个输入先互比一次,再用较小者比当前最小值、较大者比当前最大值。
每对共 3 次,整体至多 3⌊n/2⌋ 次;偶数规模需先用首对初始化,实际为 3n/2−2 次,比独立扫描的 2n−2 次少。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 第9章 中位数和顺序统计量 · 查看原书依据
Compare pairs of elements from the input first with each other, and then compare the smaller with the current minimum and the larger to the current maximum
参考来源
- 位置:《算法导论(第4版)》第 9 章 9.1 节(`OEBPS/chapter009.xhtml`,文本字符 [3000, 5000))。
- 结论依据:原文分别计算奇偶规模的初始化与每对三次比较成本。
- 原始内容:Compare pairs of elements from the input first with each other , and then compare the smaller with the current minimum and the larger to the current maximum