Which sorting algorithm is the fastest? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Which sorting algorithm is the fastest?

Ignoring memory consumption I am confused by this question, there are so many fast ones, which one to choose? For an array of numbers

26th Aug 2022, 5:50 PM
Patrick
Patrick - avatar
3 Answers
+ 5
Some more background information for your decision: https://stackoverflow.com/questions/773253/what-sort-algorithm-provides-the-best-worst-case-performance I would make some assumptions about the dataset that needs to be sorted. Is it small or large? Are you looking for best case scenario (elements are almost sorted already) or worst case (most unfavorable initial state for the specific algorithm)? Are the numbers integers of floating point? Based on these assumptions, you can pick your algorithm. Maybe you can pick multiple algorithms and test their performance on the same dataset. :) That would be an interesting exercise in any case.
26th Aug 2022, 7:54 PM
Tibor Santa
Tibor Santa - avatar
+ 5
I would think, you cannot generalize completely about the fastest algorithm. It may depend on many things, even if you talk about an array of numbers. There are many different types of numbers, even among integers and floating point values, their size (number of bits) can be different, and certain CPU architectures may be more efficient working with certain types but struggle with others. The size of the array can be significant, and also the initial state of the elements, the winning algorithm could be different if all except one element is already sorted, or the elements are in reverse order or completely random. So in short, this question can be answered best, if you consider all these specific factors.
26th Aug 2022, 6:42 PM
Tibor Santa
Tibor Santa - avatar
0
Tibor Santa thanks for the answer! That's the point - I am given a task to implement "the fastest sorting algorithm" with such conditions, but they're really too general, I don't know how to do it...
26th Aug 2022, 7:22 PM
Patrick
Patrick - avatar