ThreeWayQuickSort

Three-Way Quick Sort.

Optimized Quick Sort that handles arrays with many duplicate values efficiently by partitioning into three sections:

  • Less than pivot

  • Equal to pivot

  • Greater than pivot

Time complexity:

  • Best: O(n log n)

  • Average: O(n log n)

  • Worst: O(n²)

Space complexity:

  • O(log n) recursion stack

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 a comparator.