> For the complete documentation index, see [llms.txt](https://liuzhenglaichn.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liuzhenglaichn.gitbook.io/algorithm/sort/sorting.md).

# Sorting

<figure><img src="/files/p5mTiNfVDBTN4YTtprEh" alt=""><figcaption></figcaption></figure>

Which algorithm works best for largely sorted array?

* Insertion Sort
* Bubble Sort

<https://stackoverflow.com/a/4276118/3127828>

Only a few items => INSERTION SORT

Items are mostly sorted already => INSERTION SORT

Concerned about worst-case scenarios => HEAP SORT

Interested in a good average-case result => QUICKSORT

Items are drawn from a dense universe => BUCKET SORT

Desire to write as little code as possible => INSERTION SORT
