Reqflow
Sorting·Beginner

Insertion Sort

Time O(n²)Space O(1)
·

Insertion sort builds the sorted array one element at a time. It takes the next unsorted element, then slides it left through the already-sorted portion until it reaches the right spot. It is inefficient on large lists but fast in practice on nearly-sorted data, and it is the algorithm most people intuitively use when sorting a hand of cards.

Example: Sort 5 numbers in ascending order.

When to use this

See also

← All algorithms