Sorting

Insertion Sort

Builds a sorted array one element at a time by inserting each into its correct position.

503182139425764768

Step 1 of 58

Starting Insertion Sort. Build the sorted portion one element at a time by inserting each element into its correct position.

0
Comparisons
0
Shifts
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