Insertion sort

easy

Lift each value out, slide the larger ones right, drop it into the gap. On nearly-sorted input the inner loop barely runs - which is why real library sorts fall back to it for small or partly-ordered runs.

Best O(n)Average O(n²)Worst O(n²)Space O(1)StableIn place
Loading the insertion sort engine…

Where to go next