【问题标题】:Best and Average running time of a merge sort algorithm合并排序算法的最佳和平均运行时间
【发布时间】:2016-03-29 20:00:44
【问题描述】:

如何解释为什么归并排序算法的最佳运行时间是 Big Omega (n log n) 而平均运行时间是 Big theta (n log n)?

【问题讨论】:

    标签: algorithm sorting time merge complexity-theory


    【解决方案1】:

    Big Omega 会忽略低阶项和/或常数因子,通常使用 Big Omega 来描述上限或最坏情况。 Big Theta 应该是一个上下界和/或限定为最佳情况、平均情况、最坏情况、特定情况。

    对于纯归并排序(不是在较小组上使用某种类型排序的混合排序),移动次数是相同的,n ⌈ log2(n) ⌉(其中 ⌈⌉ 是整数上限),而数字比较的次数可能会有所不同,最坏的情况比 n ⌈ log2(n) ⌉ 小一点,最好的情况大约是其的 1/2,所以只有常数因子的差异。如果数据集元素适合寄存器(例如对整数数组进行排序),则比较时间可能会被内存访问时间隐藏(比较对整体时间影响很小或没有影响)。如果做外部归并排序(比如对大文件排序),比较时间可能会被设备读/写时间隐藏。

    维基文章:

    http://en.wikipedia.org/wiki/Big_O_notation

    http://en.wikipedia.org/wiki/Time_complexity

    http://en.wikipedia.org/wiki/Computational_complexity_theory

    http://en.wikipedia.org/wiki/Analysis_of_algorithms

    【讨论】:

      猜你喜欢
      • 2012-03-22
      • 2021-11-03
      • 1970-01-01
      • 2018-03-09
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      相关资源
      最近更新 更多