0
0
DSA C++programming~5 mins

Insertion Sort Algorithm in DSA C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASelects the smallest element and swaps it with the first
BInserts the current element into the correct position in the sorted part
CDivides the list into two halves
DSwaps the current element with the last element
What is the best-case time complexity of Insertion Sort?
AO(n)
BO(n²)
CO(n log n)
DO(log n)
Which of these is true about Insertion Sort?
AIt divides the list into sublists
BIt requires extra memory proportional to the input size
CIt always performs better than Quick Sort
DIt is stable and sorts in place
In Insertion Sort, what happens when the current element is smaller than elements in the sorted part?
AThose elements are shifted right to make space
BThe current element is discarded
CThe list is reversed
DThe current element is swapped with the first element
Which scenario causes the worst-case performance for Insertion Sort?
AList contains all equal elements
BList is already sorted
CList is sorted in reverse order
DList is empty
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.