知识卡片

普通读书笔记卡 · 3612.a.1.a

成对比较同时求极值

理解等级:中级

同时求最小值和最大值时,每两个输入先互比一次,再用较小者比当前最小值、较大者比当前最大值。

每对共 3 次,整体至多 3⌊n/2⌋ 次;偶数规模需先用首对初始化,实际为 3n/2−2 次,比独立扫描的 2n−2 次少。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《算法导论(第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