Time Space Algorithm Mnemonic Type Memory Advantages Disadvantages Description Complexity Complexity Best O(n^2) "Children’s " • Only n exchanges in the • Find smallest item and worst case, which is Selection • O(n^2) , put it in first position Avg Choose an Iterative In-place less than most other O(n^2) O(1) even in the best case • Find next-smallest item Sort element right of algorithms and put it in second "current" Worst position, etc. O(n^2)

Best O(n) • Linear time O(n) if input "Hand of Cards" Iterate through array and sort is already sorted Insertion push each item to the left as Avg Iterative In-place • One of the fastest O(n^2) O(1) long as it is smaller than its Sort Choose a position algorithms for partially left neighbour left of "current" sorted arrays Worst O(n^2)

Best

Generalisation of Avg Shell Sort Iterative In-place O(1) (using a gap > 1) Worst

Best O(n log n) Requires copy of 1. Sort left half of array Sort left, sort right • Asymptotically optimal, • Not in-place: requires input array 2. Sort right half of array Avg merge the two Recursive i.e. worst-case time O(n) extra space to hold O(n log n) O(n) Mergesort 3. Merge the two sorted sorted sub-arrays complexity is O(n log n) copy of input array Recursion levels: O(n) space sub-arrays Worst log n O(n log n)

Best • Bad worst-case time 1. Partition array around O(n log n) In-place • Optimal O(n log n) time performance of O(n^2) pivot in average case Pivot (if pivot is always min or 2. Sort sub-array left of Avg Recursive But recursive, • In practice, most of the O(n log n) O(log n) left ≤ pivot ≤ right max item) pivot therefore O(log n) time faster than any Recursion levels: • Prevent this by shuffling 3. Sort sub-array right of log n (best) to n (worst) space other algorithm Worst (with opt. log n worst) input before pivot O(n^2)

Best O(n log n)

• a Avg • W 1. P O(n log n) O(1) Worst O(n log n)

Best O(n)

Bubble • a Avg • W 1. P O(n^2) O(1) Sort Worst O(n^2)