Ruby 的排序方法使用哪种算法? [英] Which algorithm does Ruby's sort method use?
本文介绍了Ruby 的排序方法使用哪种算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用原生的 sort
方法对数组进行排序时,Ruby 使用哪种算法?
When I sort an Array using the native sort
method, which algorithm does Ruby use?
它是否依赖于数据,即,如果数据很小,则使用 X 算法,否则使用 Y 算法?
Is it data-dependant, i.e., if the data is small it uses X algorithm else it uses Y algorithm?
它是一种稳定的排序吗?平均时间复杂度是多少?
Is it a stable sort? What is the average time complexity?
推荐答案
看这里:http://www.igvita.com/2009/03/26/ruby-algorithms-sorting-trie-heaps/
然而,它本身确实使用了快速排序,平均复杂度为 n log n.
It does natively use quicksort however, which is n log n complexity on average.
这篇关于Ruby 的排序方法使用哪种算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文