3 ms·
"Why are there many sorting algorithms?" could be understood as a very deep ontological question. It is a fundamental fact that there are many different algorit
by siddboots 13y ago
"Why are there many sorting algorithms?" could be understood as a very deep ontological question. It is a fundamental fact that there are many different algorithms that can be used to sort a list, and each of those ways has some fundamental trade-offs.
Nonetheless, only a handful of those approaches are typically used in production systems, so the question could be understood instead as "Why don't we just all use some heavily optimized variant of quicksort, and forget about the rest?" One good reason (in addition to the others mentioned) is that sorting algorithms are almost the perfect teaching tool.
There are a wide variety of approaches. Most of them are almost trivially simple to understand, and many can serve as strong illustrative examples of particular theoretical concepts.
For example, sorting algorithms are a great way to demonstrate why divide and conquer approaches (like quicksort or mergesort) tend to result in `n*log(n)` time complexity, while iterative algorithms (like bubble or insertion) tend to be polynomial. Another example, studying the symmetrical relationship between quicksort and mergesort can be very revealing to the cause of the tradeoffs of each.