unj2
unj2

Reputation: 53511

Which algorithm does Ruby's sort method use?

When I sort an Array using the native sort method, which algorithm does Ruby use?

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?

Upvotes: 52

Views: 20290

Answers (1)

AlbertoPL
AlbertoPL

Reputation: 11519

Look here: 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.

Upvotes: 35

Related Questions