Most problems can be solved in more than one way. Take, for example, the sorting problem, which is related to putting the elements of a list in a specific order.
There are many sorting algorithms, and, in general, none of them is considered the best for all cases j.mp/algocomp.
There are different criteria that help us pick a sorting algorithm on a per-case basis. Some of the things that should be taken into account are listed here:
- A number of elements that need to be sorted: This is called the input size. Almost all the sorting algorithms behave fairly well when the input size is small, but only a few of them have good performance with a large input size.
- The best/average/worst time complexity of the algorithm: Time complexity is (roughly) the amount of time the algorithm takes to complete, excluding coefficients and lower-order terms. This is often the most...