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!
Time:
0:60
Lives:
❤️❤️❤️