ℹ️ Insertion Sort – Explanation
Idea— Imagine a hand of playing cards: you hold already-sorted cards on the left, then pick a new card (the key) from the right. You shift cards to the right until the correct gap is found, then insert the key. The sorted region grows by one card.
Complexity — O(n²) in the worst case (reverse-sorted array), O(n) in the best case (already sorted — only comparisons, no shifts). Better than Bubble Sort in practice for small arrays.
Properties
- Stable: Yes – equal values retain their order.
- In-place: Yes – O(1) extra memory.
1 / 30
ArrayKlick = Wert bearbeiten · Rechtsklick = löschen
64
34
25
12
22
11
90
+
_Start: Index 0 ist trivial sortiert. Insertion Sort nimmt ab Index 1 jedes Element als Schlüssel und fügt es an die richtige Stelle im sortierten linken Bereich ein.
Schlüssel (schwebend)VerglichenSortiert (final)→verschoben (Kopie)