SelectionSort

Selection Sort.

Repeatedly selects the smallest element from the unsorted portion and moves it to the beginning.

Time complexity:

  • Best: O(n²)

  • Average: O(n²)

  • Worst: O(n²)

Space complexity:

  • O(1)

Functions

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

Sorts the array using natural ordering.

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

Sorts the array using the provided comparator.