Different algorithms sort at different speeds, use different amounts of memory, and are better suited to different applications. It is sort of like saying “why can’t we just use one wheel for everything”; while the wheels on luggage and the wheels on an airplane are both wheels you wouldn’t want to use the same one for both.
It’s like saying what’s the point of having so many different cars if the primary objective is to get from one place to another. Why can’t there just be one type of car?
Some people want to get there the fastest with no regards to fuel usage (memory usage).
Others want good fuel economy and can handle going a little slower.
Sometimes you have to handle transporting a lot of people so you’re limited to larger vehicles rather than driving multiple vehicles.
You may want a different car for road trips compared to daily commutes.
Generally we want to sort as fast as possible. We rank how fast algorithms are with big O notation, you’ll see things like O(n^2), O(n * log (n)) etc. This says how much slower the algorithm gets as he number of items (n) you are sorting gets bigger. So you’d think O(n^2) is always slower than O(n * log (n)), but that isn’t necessarily true for small values of n. So if you are sorting just a few items, the ‘slower’ algorithm might actually be better because there is less setup time.
Other algorithms may have other weaknesses. They may perform worse poorly if there are a lot of duplicate values. They may perform poorly if the data is almost sorted.
You may want a stable sort. That is if you have two equal values, their order isn’t changed.
Generally, you can use the standard sort algorithm that comes with your language of choice. However, if you run into performance problems, you may need a specialized sort.
Different algorithms sort at different speeds, use different amounts of memory, and are better suited to different applications. It is sort of like saying “why can’t we just use one wheel for everything”; while the wheels on luggage and the wheels on an airplane are both wheels you wouldn’t want to use the same one for both.
Different algorithms sort at different speeds, use different amounts of memory, and are better suited to different applications. It is sort of like saying “why can’t we just use one wheel for everything”; while the wheels on luggage and the wheels on an airplane are both wheels you wouldn’t want to use the same one for both.
Generally we want to sort as fast as possible. We rank how fast algorithms are with big O notation, you’ll see things like O(n^2), O(n * log (n)) etc. This says how much slower the algorithm gets as he number of items (n) you are sorting gets bigger. So you’d think O(n^2) is always slower than O(n * log (n)), but that isn’t necessarily true for small values of n. So if you are sorting just a few items, the ‘slower’ algorithm might actually be better because there is less setup time.
Other algorithms may have other weaknesses. They may perform worse poorly if there are a lot of duplicate values. They may perform poorly if the data is almost sorted.
You may want a stable sort. That is if you have two equal values, their order isn’t changed.
Generally, you can use the standard sort algorithm that comes with your language of choice. However, if you run into performance problems, you may need a specialized sort.
It’s like saying what’s the point of having so many different cars if the primary objective is to get from one place to another. Why can’t there just be one type of car?
Some people want to get there the fastest with no regards to fuel usage (memory usage).
Others want good fuel economy and can handle going a little slower.
Sometimes you have to handle transporting a lot of people so you’re limited to larger vehicles rather than driving multiple vehicles.
You may want a different car for road trips compared to daily commutes.
Latest Answers