What is the structured English for insertion sort?
How to write an insertion sort in pseudocode?
for i = 1 to A.length – 1
key = A[i]
j = i - 1
while j >= 0 AND A[j] > key
A[j + 1] = A[j]
j–
endWhile
A[j + 1] = key
next i
Where does an insertion sort start?
At the second index, since the first is already sorted.
What is the difference between an insertion sort and a bubble sort?
The algorithm shifts values along. It does not swap values. (Bubble sort swaps, insertion sort shifts).
What are advantages of an insertion sort?
What is a disadvantage of an insertion sort?
It does not scale well so it’s not good for large data sets.
What is the worst case scenario for an insertion sort? (ascending)
Worst case scenario for ascending sort is when the values are in descending order
What is the best case scenario for an insertion sort?
Best case scenario is the data is already sorted