[英]Which algorithm does Ruby's sort method use?
When I sort an Array using the native sort
method, which algorithm does Ruby use? 当我使用本机
sort
方法对数组进行sort
,Ruby使用哪种算法?
Is it data-dependant, ie, if the data is small it uses X algorithm else it uses Y algorithm? 它是数据依赖的,即,如果数据很小,它使用X算法,否则它使用Y算法?
Is it a stable sort? 这是稳定的吗? What is the average time complexity?
平均时间复杂度是多少?
Look here: http://www.igvita.com/2009/03/26/ruby-algorithms-sorting-trie-heaps/ 请看这里: http : //www.igvita.com/2009/03/26/ruby-algorithms-sorting-trie-heaps/
It does natively use quicksort however, which is n log n complexity on average. 它本身使用quicksort,但平均而言是n log n复杂度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.