I have been looking at the Scala documentation but so far I have found no answer to my question, namely what sorting algorithm is used by the method
scala.collection.immutable.Vector.sorted
The documenation says it is a stable sort, but not the actual algorithm used. Is it a merge sort?
The
sortedmethod is implemented inSeqLike, and seems to usejava.util.Arrays.sortfor its sorting. It builds an array from the vector, then invokesArrays.sortand then converts it back, it seems. According to the Java 6 documentation, it therefore uses quicksort:For Java 7, the algorithm seems to have change (again, citing the docs):
Scala’s
SeqLike#sortedsource (taken from GitHub):