Insertion Sort works like sorting playing cards in your hand! It treats the 1st card on the far left as already sorted, then picks up each remaining card one-by-one from left to right and inserts it into its exact spot.
How it Works Step-by-Step:
1Pick the Next Card (Left to Right): Consider the 1st card on the far left as a 1-card sorted hand. Move to the 2nd card and pick it up as your target card to insert.
2Compare Backwards & Make Room: Look left into your sorted cards. If a card in your hand is bigger than your target card, slide that bigger card one step to the right to open up a gap.
3Insert Into Open Gap: As soon as you hit a smaller card (or reach the start of the row), drop your target card right into the open gap!
š Real-World Analogy: Organizing Playing Cards in Your Hand
Imagine holding cards [3, 5, 8] already sorted in your left hand. You pick up the next card 6 from the table. You compare 6 with 8 ā since 8 is bigger, you slide 8 right to make a gap. Next, you compare 6 with 5 ā since 5 is smaller, you stop and insert 6 right into the gap between 5 and 8!