Why would you use anything other than Quicksort?

I read through all the sort algorithms listed here: Learn Data Structures and Algorithms

It seems like Quicksort is the fastest and what many languages use as their default built-in sorts. If that is the case, why would I use a much slower sort like Insertion or Selection?

Hi @qwerty_dvorak - there are two reasons:

  1. Valid Reason #1: You have fixed memory and need to sort without using up any extra memory. Insertion sort, for example, takes up a constant amount of memory to do its sorting.

  2. Sorta Valid Reason #2: Quicksort is more complicated to implement. For small-ish amounts of data, both insertion sort and selection sort are as fast if not faster than quicksort. If your data is partially sorted already, you can get even faster than the default Quicksort case with smaller amounts of data.

Hope this helps :slight_smile:


1 Like

Quicksort is undoubtedly efficient, but sometimes, the input data distribution can impact its performance. Other sorting algorithms like Merge Sort or Heap Sort might be preferable for datasets with predictable patterns, as they offer consistent time complexity regardless of input.