Insertion Sort Visualizer
Follow Insertion Sort as it grows a sorted prefix through comparisons and shifts, with playback controls and live operation metrics.
Comma-separated numbers, up to 20 values.
Live operation
sorted
Comparisons
0
Moves / writes
0
Confirmed sorted
1 / 5
Algorithm notes
What to watch for
Insertion Sort treats the left side of the array like a growing hand of cards. Each new value compares backward and shifts left until the prefix is ordered.
Concept guide
Review the mental model, tradeoffs, and practical use cases after you experiment.
Insertion Sort Complete Info Card
Insertion Sort builds the final sorted array one element at a time by repeatedly taking the next element and inserting it into its correct position within the sorted portion.
Algorithm Characteristics
Time Complexity (Best)
When array is already sorted
Time Complexity (Average)
Typical case with random data
Time Complexity (Worst)
When array is reverse sorted
Space Complexity
In-place sorting algorithm
Stable
Maintains relative order of equal elements
Adaptive
Efficient for nearly-sorted data
Sorting Process Steps
Start with second element as key
Compare key with sorted elements to its left
Shift elements greater than key right
Insert key in correct position
Repeat for all elements
Early termination in sorted portions
Comparison with Other O(n²) Sorts
| Algorithm | Swaps (Worst Case) | Best Case |
|---|---|---|
| Bubble Sort | O(n²) | O(n) |
| Selection Sort | O(n) | O(n²) |
| Insertion Sort | O(n²) | O(n) |
Optimal Use Cases
- •Small datasets (n ≤ 50)
- •Nearly-sorted data (adaptive)
- •Online sorting (data arriving sequentially)
When to Avoid
- •Large random datasets
- •Performance-critical applications
- •When memory is not constrained (consider Merge Sort)