Insertion Sort

Build the sorted array one element at a time by inserting each element into its correct position

Size:
Speed:
Unsorted
Comparing
Shifting
Sorted

About Insertion Sort

Time Complexity:

  • Best: O(n) - already sorted
  • Average: O(n²)
  • Worst: O(n²) - reverse sorted

Space Complexity: O(1)

Stable: Yes

How It Works

Insertion Sort builds the final sorted array one item at a time. It picks the next element and inserts it into the correct position within the already sorted portion.

Like sorting playing cards in your hand, you pick up one card at a time and place it in the right spot among the cards you're already holding.

💡 Tip: Very efficient for small arrays or nearly sorted data!