One Task, Several Sorting Algorithms
Goal: Describe the required result before choosing the steps that produce it.
Sorting means putting items in a chosen order. In ascending order, smaller values come first. In descending order, larger values come first. The key is the value we compare to decide which item should come first.
An algorithm must produce that order and keep all the original items. Losing an item is not a correct sorting method, even if the remaining items look ordered. Repeated values must keep their correct number of occurrences.
Several algorithms solve this same task. In the next lesson, we will follow Selection Sort and Insertion Sort one move at a time. First, learn how to describe the task and its constraints; you do not need to memorise a long list of algorithm names.
A map of names, not a ranking
| Group | Examples | What to notice now |
|---|---|---|
| Direct comparison methods | Selection Sort, Insertion Sort | Simple steps; the usual versions have quadratic worst-case time |
| Other comparison methods | Merge Sort, Quick Sort, Heap Sort | Their guarantees depend on the algorithm and the case being analysed |
| Other names you will meet | Bubble Sort, Comb Sort, Shell Sort | A similar name does not imply the same running time |
| Distribution methods | Counting Sort, Radix Sort, Bucket Sort | These use properties of the values, their digits, or their distribution |
There is no rule that every algorithm in one row is always better than every algorithm in another row. For example, ordinary Quick Sort can take quadratic time in the worst case; is not a guarantee for every execution of every version.
Remember: Sorting is the task. Selection Sort and Insertion Sort are different ways to do that task.