Sorting algorithms | Sololearn: Learn to code for FREE!


Sorting algorithms

Why using multiple sorting algorithms? If I understood correctly main difference between them is in speed. So why not use fastest one all the time? Is there another factor other than speed?

12/5/2017 9:04:20 AM


5 Answers

New Answer


✓✓easy way ✓✓with iteration counter ✓✓running time of algorithms ✓✓please check this once


@Elva, thank you for make my answer as best!! 😊😊 👍👍


definitely speed is a factor. And they are not useful on every type of input. suppose you have 2 elements in a list. binary search may not be a good exqmple because it will take more time to declare high & low. Instead a linear search would be way more useful. Now if you have 200 or 2000 elements then the time taken by declaring high & low will decrease time taken to search.


Here is an example: Notice how the slower bubble sort is actually more efficient for a smaller sized array.


sorting algorithms are described in cases: best, worst. Sometimes it is better to have a constant complexity (best = worst). for example in medical devices you choose a maybe slower algorithm if the worst case is faster. In very tight timed applications it is often good to know/estimate how long it will take, instead of being fast on one case an slow on another. in some szenerio you are good to be fast in good cases and you don't care about worst cases (like on a website, you want to make it as fast as possible but normally user accept it if it lacks sometimes)