Algomination
Data Structures
AboutContact

Algomination

Learn algorithms and data structures through smooth, interactive visualizations.

SortingSearchingArray AlgorithmsData StructuresAboutContact

© 2026Algomination. Created by Omang Rawat & Rahul Soni.

Omang Rawat
Rahul Soni
All sorting algorithms

Insertion Sort

Time O(n²)Space O(1)

Builds a sorted prefix by inserting each new element into its correct spot.

6
2
9
1
7
3
8
Starting Insertion Sort. The first element is a sorted prefix.
Step 1 / 36
SortedKey / ActiveComparingSwapping

About Insertion Sort

Builds a sorted prefix by inserting each new element into its correct spot.

Time complexity: O(n²). Space complexity: O(1).

How it works, step by step

Core idea — Take each new element and slide it left into its correct spot among the already-sorted prefix.

What each pass accomplishes — After inserting the k-th element the first k+1 elements are sorted relative to each other — that sorted prefix grows by one each step (its values may still shift once later elements arrive).

Use the interactive visualizer above to run Insertion Sort on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.