TimSort

object TimSort(source)

Tim Sort.

Hybrid sorting algorithm derived from Merge Sort and Insertion Sort. It identifies already sorted runs and merges them efficiently.

Time complexity:

  • Best: O(n)

  • Average: O(n log n)

  • Worst: O(n log n)

Space complexity:

  • O(n)

Functions

Link copied to clipboard
fun <T : Comparable<T>> sort(array: Array<T>)

Sorts using natural ordering.

fun <T> sort(array: Array<T>, comparator: Comparator<T>)

Sorts using the provided comparator.