Recall & Review
beginner
What is the main 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
How does Insertion Sort handle the elements during sorting?
It divides the list into a sorted and unsorted part. It takes elements from the unsorted part and inserts them into the correct position in the sorted part by shifting larger elements to the right.
Click to reveal answer
intermediate
What is the worst-case time complexity of Insertion Sort and when does it occur?
The worst-case time complexity is O(n²), which happens when the input list is sorted in reverse order, causing maximum shifts for each insertion.
Click to reveal answer
intermediate
Show the JavaScript code snippet for the core insertion step inside the Insertion Sort.
for (let j = i - 1; j >= 0 && arr[j] > key; j--) { arr[j + 1] = arr[j]; } arr[j + 1] = key;Click to reveal answer
beginner
Why is Insertion Sort efficient for nearly sorted or small lists?
Because it only shifts elements when necessary, so if the list is almost sorted, fewer shifts happen, making it run faster than more complex algorithms on small or nearly sorted data.
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 sorted elements.
What is the best-case time complexity of Insertion Sort?
✗ Incorrect
The best case is when the list is already sorted, so Insertion Sort only makes one pass with no shifts, resulting in O(n) time.
Which of these is true about Insertion Sort?
✗ Incorrect
Insertion Sort is stable because it does not change the relative order of equal elements.
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 moved one position to the right to make space for insertion.
Which scenario causes the worst performance for Insertion Sort?
✗ Incorrect
When the list is sorted in reverse order, every element must be shifted, causing O(n²) time.
Explain how Insertion Sort works step-by-step on a small list.
Think about how you sort playing cards in your hand.
You got /4 concepts.
Describe the time complexity of Insertion Sort and when it performs best and worst.
Consider how many moves are needed depending on the order of elements.
You got /4 concepts.