Sorting Algorithms study song
Quick answer
Sorting algorithms put items in order, and every data structures course compares them by time complexity, extra memory, and whether equal items keep their original order, which is called stability. Expect questions that give you a half-sorted array and ask for the next pass of bubble or insertion sort, or ask which algorithm is best when the data is nearly sorted.
The facts are many small contrasts, which is why a rap with one bar per algorithm works well. Each bar can name the algorithm, its typical cost and its one quirk, such as quicksort's bad pivot or merge sort's extra array. Rhyme keeps the pairings together so they do not blur on exam day.
5 facts to know about sorting algorithms
- 1Merge sort is stable, runs in O(n log n) time, and needs O(n) extra space.
- 2Quicksort averages O(n log n) but degrades to O(n^2) when the pivot is repeatedly the smallest or largest element.
- 3Insertion sort is O(n) on already sorted input and O(n^2) in the worst case.
- 4Heap sort is O(n log n) in every case and sorts in place, but it is not stable.
- 5Any comparison-based sort needs at least O(n log n) comparisons in the worst case.














