CZ
CalcyZone
computer-science Verified Precision Tool

Insertion Sort Visualizer & Step Generator

Interactive Insertion Sort step generator showing array shifts and key element insertion.

Interactive Algorithm Visualizer

Insertion Sort

Enter your custom input data → Run the real algorithm engine → Observe step transitions.

⚙️ Customize Algorithm Input Data

Step 1 of 19⚡ Algorithm Running
WHAT HAPPENED?

Sub-array at index 0 is trivially sorted.

WHY?

Algorithm state rule requirement

WHAT CHANGED?

State pointers updated

64
[0]
25
[1]
12
[2]
22
[3]
11
[4]

Mathematical Formula

Insert key arr[i] into sorted subsegment arr[0..i-1]

Overview & Explanation

Insertion sort builds the final sorted array one item at a time, similar to sorting playing cards in hand.

How It Works

  • Iterate from arr[1] to arr[n-1].
  • Compare current key element with preceding elements.
  • Shift elements greater than key one position ahead.

Practical Applications

  • Fast sorting for nearly-sorted arrays
  • Online real-time stream sorting

Insertion Sort Example

Sorting [12, 11, 13, 5, 6]

1

Insert 11

Shift 12

= [11, 12, 13, 5, 6]
2

Insert 5

Shift 13, 12, 11

= [5, 11, 12, 13, 6]

Frequently Asked Questions

When is Insertion Sort efficient?
Insertion Sort is very fast for small arrays (n < 15) or nearly sorted data.