Insertion Sort Visualizer

Watch how Insertion Sort builds the sorted array one element at a time by inserting each element into its correct position.

Time: O(n²)
Space: O(1)
Stable: Yes
Adaptive: Yes
Fast (200ms)Slow (2000ms)
Progress: Step 1 of 0Pass 0 of 0
640
341
252
123
224
115
906
Unsorted
Current Key
Insert Position
Comparing
Shifting
Sorted

Current Step:

Click Start to begin the Insertion Sort visualization

Algorithm Details

Best Case:O(n)
Average Case:O(n²)
Worst Case:O(n²)
Space:O(1)
Stable:Yes
Adaptive:Yes

When to Use Insertion Sort

  • Small datasets (≤ 50 elements)
  • Nearly sorted or partially sorted data
  • Online sorting (sorting data as it arrives)
  • When stability is required
  • Large datasets (poor worst-case performance)

Real-world Applications

  • Hybrid sorting in advanced algorithms (like Timsort)
  • Real-time data processing systems
  • Sorting small subarrays in divide-and-conquer algorithms
  • Playing cards sorting (most natural way humans sort)