Insertion sort

Insertion sort · O(n²)

Elements Active CompletePlayed 0.0 s · same input

Insertion sort

Insertion sort
O(n²)
Operations0
Comparisons0
Writes0

Each comparison or write counts as 1 operation. Playback time is not execution time.

← Back to six-algorithm comparison
How it works +

Treat the left side as a sorted hand of cards. Take the next number and insert it in the right place to the left. Especially effective on nearly sorted data.

Extra space: O(1); Stable. Each comparison or main-array write counts as 1 operation.