SortingLab

Insertion sort

How it works

Insertion Sort builds a sorted list one item at a time, like sorting playing cards in your hand! Each new card is placed in the correct position relative to the already sorted part.

  • 🔹 Take one element → Compare with sorted ones → Insert it in the right spot among the sorted elements → Repeat until sorted.

  • 🔹 Best case: Already sorted? ✅ Only takes O(n) time!

  • 🔹 Worst case: Needs to shift many elements, runs in O(n²).

  • 🔹 Why learn it? It's efficient for small lists and nearly sorted data.

👀 Think of it as: Organizing cards in a card game.

How it works in code


                        

How to play

Goal: Move each new element into the correct position.

Buttons:

  • Skip ⏭️ → Moves to the next element in the list.

  • Left ⬅️ → Moves the current element left one step at a time until it reaches its correct position.

  • Submit ✅ → Checks if the list is fully sorted.

👀 Tip: Keep shifting left until the element is in its correct place!

Game options

Choose game preferences:

Choose game mode:

Choose game difficulty (amount of elements):

Time:

0:60

Lives:

❤️❤️❤️

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Game over!