Sorting algorithms | Sololearn: Learn to code for FREE!

+10

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

Elva

5 Answers

New Answer

+11

✓✓easy way ✓✓with iteration counter ✓✓running time of algorithms ✓✓please check this once https://code.sololearn.com/cY7SC8lmidwy/?ref=app

+10

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

+5

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.

+5

Here is an example: https://code.sololearn.com/cMrvFWe4Cb9J/?ref=app Notice how the slower bubble sort is actually more efficient for a smaller sized array.

+1

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)