Options
All
  • Public
  • Public/Protected
  • All
Menu

External module sort

Index

Type aliases

Functions

Type aliases

SortFn

SortFn: function

Sort function type for sorting algorithms, mutate original collection

Type declaration

    • Parameters

      Returns void

Functions

qSort

  • qSort<T>(collection: T[], comparator?: ComparatorFn<T>): void
  • Quicksort (unstable, in-place implementation)

    Quicksort is a divide and conquer algorithm. Quicksort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays.

    Quicksort source: commons.wikimedia.org

    Complexity

    Case BigO
    Worst-case performance O(n^2)
    Best-case performance O(n log n) (simple partition) or O(n) (three-way partition and equal keys)
    Average performance O(n log n)
    Worst-case space complexity O(n) auxiliary (naive) O(log n) auxiliary

    Reference

    import { qSort } from '@pencroff/ts-algorithms/dist/algorithm/sort/qsort';
    qSort([11, 5, 8]), // [5, 8, 11]

    Type parameters

    • T

    Parameters

    Returns void