算法nth

编程入门 行业动态 更新时间:2024-10-13 20:15:05
本文介绍了算法nth_element的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近发现,存在一个名为 nth_element 在STL方法。引述说明:

I have recently found out that there exists a method called nth_element in the STL. To quote the description:

Nth_element类似于   partial_sort,因为它部分地   承揽了一系列的元素:它   排列范围[第一个,最后一个),例如   该元素由指向   迭代的第n个相同的   元素,这将是在那个位置   如果整个区间[first,last)中有   被排序。此外,没有任何的   范围内的元素[n次,最后一次)是   小于任何在元素   范围[第一次,第n次)。

Nth_element is similar to partial_sort, in that it partially orders a range of elements: it arranges the range [first, last) such that the element pointed to by the iterator nth is the same as the element that would be in that position if the entire range [first, last) had been sorted. Additionally, none of the elements in the range [nth, last) is less than any of the elements in the range [first, nth).

这号称有平均为O(n)的复杂性。如何算法的工作?我找不到它的任何解释。

It claims to have O(n) complexity on average. How does the algorithm work? I could not find any explanation for it.

推荐答案

这就是所谓的一个选择算法和维基百科有一个体面的页面就可以了:en.wikipedia/wiki/Selection_algorithm

It's called a selection algorithm and wikipedia has a decent page on it: en.wikipedia/wiki/Selection_algorithm

另外阅读顺序统计:en.wikipedia/wiki/Order_statistic

更多推荐

算法nth

本文发布于:2023-11-29 22:22:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647801.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   nth

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!