0
0
DSA Javascriptprogramming~5 mins

Insertion Sort Algorithm in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASwaps the first and last elements
BInserts the current element into the correct position in the sorted part
CDivides the list into halves
DFinds the maximum element and places it at the end
What is the best-case time complexity of Insertion Sort?
AO(n)
BO(n log n)
CO(n²)
DO(log n)
Which of these is true about Insertion Sort?
AIt is the fastest sorting algorithm for large lists
BIt always uses extra memory
CIt is a stable sorting algorithm
DIt sorts by dividing the list into two halves
In Insertion Sort, what happens when the current element is smaller than elements in the sorted part?
AElements larger than the current element are shifted right
BThe current element is discarded
CThe list is reversed
DThe current element is swapped with the last element
Which scenario causes the worst performance for Insertion Sort?
AList is empty
BList is already sorted
CList has all equal elements
DList is sorted in reverse order
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.