Comparison of the complexity of algorithms.
2.3.1 Algorithms
Algorithms — Note 4 of 6
Candidates need to know the best and worst case complexities for the searching and sorting algorithms. Candidates need to understand the difference between best, average and worst case complexity and why these can differ for an algorithm.
You need to compare the standard searching and sorting algorithms using Big O notation, including their best, average and worst cases, and explain why these can differ.
The input that makes the algorithm do the least work, e.g. the item being searched for is first in the list.
The input that makes the algorithm do the most work, e.g. the item is last or not present.
The expected work over typical inputs.
Algorithm Best Average Worst Extra space
Linear search O(1) O(n) O(n) O(1)
Binary search O(1) O(log n) O(log n) O(1)
Bubble sort O(n) O(n^2) O(n^2) O(1)
Insertion sort O(n) O(n^2) O(n^2) O(1)
Merge sort O(n log n) O(n log n) O(n log n) O(n)
Quick sort O(n log n) O(n log n) O(n^2) O(log n)