Package-level declarations

Functions

Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.medianOfThree(low: Int, high: Int): Int

Median of three finds the pivot by taking the median of the first, middle and last element.

Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.partitionDutchFlag(low: Int, high: Int, pivotIndex: Int): Pair<Int, Int>
Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.partitionHoare(low: Int, high: Int): Int
Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.partitionLomuto(low: Int, high: Int): Int
Link copied to clipboard
fun <T : Comparable<T>> quickSort(list: MutableList<T>, low: Int = 0, high: Int = list.size - 1)

Inventor: Tony Hoare Worst complexity: n^2 Average complexity: nlog(n) Best complexity: nlog(n) Method: Partitioning Stable: No

Link copied to clipboard

Dutch national flag partitioning strategy helps to organize duplicate elements in a more efficient way.

Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.quicksortHoare(low: Int, high: Int)

Hoare’s partitioning chooses the first element as its pivot.

Link copied to clipboard
Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.quicksortLomuto(low: Int, high: Int)

Lomuto’s partitioning chooses the last element as the pivot.

Link copied to clipboard
fun <T : Comparable<T>> MutableList<T>.quickSortMedian(low: Int, high: Int)
Link copied to clipboard

The naive partitioning creates a new list on every filter function; this is inefficient.