Comparing insertion, merge and quick sort
Question
Describe how insertion sort, merge sort and quicksort work and compare their time and space complexity.
Short answer
Insertion sort is , merge sort always, quicksort on average. Insertion sort inserts each element into the sorted prefix: when nearly sorted, in place. Merge sort splits in half, sorts each and merges: guaranteed and stable but needs extra memory. Quicksort partitions around a pivot and recurses: fast in practice and in place, but with bad pivots.
Adapted from Zhou, A Practical Guide to Quantitative Finance Interviews, sec. 7.1 Algorithms, 'Sorting algorithm', p.173; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solution