logo
SEE ALGORITHMS
    Bubble Sort
    Insertion Sort
    Selection Sort
    Heap Sort
    Merge Sort
    Quick Sort
    Radix Sort

Insertion Sort

Ever organized a hand of playing cards? Then you already know Insertion Sort! This algorithm takes each element from the unsorted part and slides it into its correct position in the sorted part. It is like placing a new card in the right spot of a sorted hand, making it intuitive and efficient for small dataset, especially for partially sorted lists.

Things to Observe

  • Inserting into Place: Watch how each element is picked from the unsorted part and slides into its correct position in the sorted part on the left, just like organizing a hand of playing cards.
  • Adaptive Performance: Try visualizing a nearly sorted list. You'll notice Insertion Sort runs much faster because it only has to shift a few elements for each insertion. This makes it very efficient for lists that are already mostly sorted.
for i = 1 to (n - 1):
    key = arr[i]
    j = i - 1
    while j >= 0 and arr[j] > key:
        arr[j + 1] = arr[j]
        j = j - 1
    arr[j + 1] = key
Select number of elements:  

Curious to Learn More?

Hand-picked resources to deepen your understanding

Beginner Friendly
Grokking Algorithms

A friendly, fully illustrated guide. The best starting point for visual learners.

Practical Guide
A Common-Sense Guide to Data Structures and Algorithms

A practical guide with clear explanations and real-world examples.

Deep Dive
Introduction to Algorithms

The definitive guide (CLRS). Comprehensive and rigorous, perfect for deep diving into theory.

As an Amazon Associate, I earn from qualifying purchases. This helps support the site at no extra cost to you.

© 2025 SEE Algorithms. Code licensed under MIT, content under CC BY-NC 4.0.