F
F
foonfyrick2021-04-04 13:52:38
Kotlin
foonfyrick, 2021-04-04 13:52:38

.sort() which sort method does it use? binary insertion sort?

I looked in the code, and everything goes so deep, one sort calls another, I'm not sure, but in the end it comes to the binarySort method, which says:
Sorts the specified portion of the specified array using a binary
* insertion sort. This is the best method for sorting small numbers
* of elements. It requires O(n log n) compares, but O(n^2) data
* movement (worst case).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-04-04
@foonfyrick

In theory, it depends on what you call this method from.
TimSort for an array of objects, qsort for an array of primitives, for example. Well, I googled it . And right off the bat I would just say TimSort. Surely there, if you dig, there are some other super-optimizations.
What you found is most likely a piece of TimSort .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question