eli5 what’s the point of having so many sorting algorithms if the primary objective is to sort, i mean why can’t we just use one algorithm for all

592 views

eli5 what’s the point of having so many sorting algorithms if the primary objective is to sort, i mean why can’t we just use one algorithm for all

In: 6

24 Answers

Anonymous 0 Comments

In practice there is basically only one algorithm used, and that would be the Tim sort. It’s the go to if you’re writing in a high level language.

In languages closer to the hardware with less abstraction you can sometimes use something else. But every algorithm is a bit different.

For example quick sort uses less memory than Tim sort, but the advantage of Tim sort is that if you give it already sorted numbers to sort (or almost sorted), it’s gonna take way less time to do so than if you gave it an unsorted array of numbers. Unlike with quick sort.

… and there are others with other caveats

But the answer to the question why do so many get taught is that it really does teach how to write all sorts of other algorithms and ace that LeetCode problem.

You are viewing 1 out of 24 answers, click here to view all answers.