【问题标题】:algorithm for nth_element第 n 个元素的算法
【发布时间】:2011-01-24 10:48:01
【问题描述】:

我最近发现在 STL 中有一个名为 nth_element 的方法。引用描述:

Nth_element 类似于 partial_sort,因为它部分 订购一系列元素:它 排列范围 [first, last) 这样 指向的元素 迭代器 nth 与 将在该位置的元素 如果整个范围 [first, last) 有 被排序。此外,没有一个 [nth, last) 范围内的元素是 小于中的任何元素 范围 [第一个,第 n 个)。

它声称平均具有 O(n) 复杂度。算法是如何工作的?我找不到任何解释。

【问题讨论】:

    标签: c++ algorithm median nth-element


    【解决方案1】:

    这叫做选择算法,维基百科上有一个不错的页面:http://en.wikipedia.org/wiki/Selection_algorithm

    另请阅读订单统计信息:http://en.wikipedia.org/wiki/Order_statistic

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      • 2017-11-27
      • 2010-09-20
      相关资源
      最近更新 更多