Easy · O(n²) worst, O(n) best
Insertion Sort quiz
Answer the questions in your own time, change a pick whenever you like, then hand in to see your score and why each answer is right. Nothing is saved or sent.
Questions (10)
- Viewing
- Answered
- Not answered
Insertion sort has inserted the keys at i = 1, 2 and 3 of [5, 2, 8, 1, 7, 3, 6, 4]. What does the array look like now?
What does the loop invariant of insertion sort say at the start of each pass?
How many shifts does insertion sort make on [5, 2, 8, 1, 7, 3, 6, 4]?
The array [1, 2, 3, 4, 5, 6, 7, 8] is already sorted. How many comparisons does insertion sort make?
How many comparisons does it take to sort [1, 2, 3, 5, 4]?
Why does the listing compare with > and not >=?
How many array writes does the listing make to sort the reversed [8, 7, 6, 5, 4, 3, 2, 1]?
Binary insertion sort finds each gap with a binary search. What does that improve?
Why do TimSort and introsort finish small runs with insertion sort?
What goes wrong if the listing skips const key = values[i] and compares with values[i] directly?
Progress
0 / 10 questions0%
10 questions left
Quiz details
- Total questions
- 10
- Answered
- 0
- Not answered
- 10
Take it further
- AnimationSorting
Insertion Sort Animation
A card lifted out of the row, bigger bars sliding right underneath, a gap that travels left: insertion sort as shifting, never swapping
Free
