← SortingInsertion Sort
Builds a sorted array one element at a time by inserting each into its correct position.
Step 1 of 58
Starting Insertion Sort. Build the sorted portion one element at a time by inserting each element into its correct position.
▶Algorithm
InsertionSort(arr):
for i = 1 to n−1:
key = arr[i]; j = i−1
while j ≥ 0 and arr[j] > key:
arr[j+1] = arr[j]; j−−
arr[j+1] = key
// sorted
Legend
Key / comparing
Shifting right
Sorted
Unsorted
1 / 58Speed