Questions: Insertion Sort Algorithm

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

An array of 1,000 elements has exactly 5 elements out of place. Which sorting algorithm will likely perform closest to O(n) on this input?

AMerge sort, because it is always O(n log n) regardless of input
BInsertion sort, because nearly-sorted arrays have few inversions and it removes exactly one inversion per operation
CSelection sort, because it scans linearly and skips sorted regions
DHeap sort, because its heapify step is optimized for small perturbations
Question 2 Multiple Choice

Why do real-world sorting libraries like Python's Timsort often switch to insertion sort for subarrays smaller than about 64 elements, even though insertion sort is O(n²)?

AInsertion sort has lower memory usage than merge sort, which is the bottleneck at small sizes
BInsertion sort is stable and Timsort requires stability throughout
CAt small n, insertion sort's low constant factors and cache-friendly sequential access beat the overhead of recursive O(n log n) algorithms
DInsertion sort is parallelizable in ways merge sort is not
Question 3 True / False

Insertion sort runs in O(n) time when the input array is already sorted.

TTrue
FFalse
Question 4 True / False

Insertion sort is typically slower in practice than merge sort or quicksort, because those algorithms have better asymptotic complexity.

TTrue
FFalse
Question 5 Short Answer

What is the relationship between the number of inversions in an array and the amount of work insertion sort performs? Why does this explain its O(n) best case and O(n²) worst case?

Think about your answer, then reveal below.