The sorting algorithms we already know!

  • Recall the process and efficiency of bubble, selection, insertion, and heap sort.
SortDescriptionWorst Case
BubbleCompare two elements at a time and swap if the second element is larger than the first. Repeat until sorted.$\Omicron(n^2)$
SelectionFind largest, swap with the last element then, find the second largest, swap with the second last element, and so on (repeat for each position).$\Omicron(n^2)$
InsertionDivide the sequence into sorted and unsorted portions. The sorted portion is empty at the start. Remove the first element from unsorted and place it into the sorted portion such that it remains sorted. Repeat until the unsorted portion is empty.$\Omicron(n^2)$
HeapBuild a max-heap from the sequence (bottom-up heapify). Remove the max and swap it to the end of the collection where the "leaf" was removed. Repeat the last step $n-1$ times.$\Omicron(n \lg n)$