Recall & Review
beginner
What is the basic idea behind the Insertion Sort algorithm?
Insertion Sort builds the final sorted list one item at a time by taking each element and inserting it into its correct position among the previously sorted elements.
Click to reveal answer
beginner
What is the time complexity of Insertion Sort in the worst case?
The worst-case time complexity of Insertion Sort is O(n²), where n is the number of elements to sort. This happens when the list is sorted in reverse order.
Click to reveal answer
intermediate
How does Insertion Sort behave with nearly sorted data?
Insertion Sort performs very efficiently on nearly sorted data, with a time complexity close to O(n), because fewer shifts are needed to insert elements in their correct positions.
Click to reveal answer
beginner
Show the step-by-step insertion of the element 5 into the sorted list [1, 3, 7, 9] using Insertion Sort.
Step 1: Compare 5 with 9, shift 9 right.<br>Step 2: Compare 5 with 7, shift 7 right.<br>Step 3: Compare 5 with 3, stop shifting.<br>Step 4: Insert 5 after 3.<br>Resulting list: [1, 3, 5, 7, 9]
Click to reveal answer
beginner
What is the space complexity of Insertion Sort?
Insertion Sort has a space complexity of O(1) because it sorts the list in place without needing extra space proportional to the input size.
Click to reveal answer
What does Insertion Sort do at each step?
✗ Incorrect
Insertion Sort takes the current element and inserts it into the correct position among the already sorted elements.
What is the best-case time complexity of Insertion Sort?
✗ Incorrect
When the list is already sorted, Insertion Sort only compares each element once, resulting in O(n) time.
Which of these is true about Insertion Sort?
✗ Incorrect
Insertion Sort is stable (preserves order of equal elements) and sorts the list in place without extra memory.
In Insertion Sort, what happens when the current element is smaller than elements in the sorted part?
✗ Incorrect
Elements larger than the current element are shifted right to insert the current element in the correct position.
Which scenario causes the worst-case performance for Insertion Sort?
✗ Incorrect
When the list is sorted in reverse order, every element must be compared and shifted, causing O(n²) time.
Explain how Insertion Sort works step-by-step on a small list.
Think about sorting playing cards in your hand.
You got /4 concepts.
Describe the time and space complexity of Insertion Sort and when it performs best.
Consider how many comparisons and shifts happen depending on input order.
You got /4 concepts.