What is Insertion Sort?

Insertion Sort works the way you sort playing cards in your hand.

Idea:


Step-by-Step Example

Given array:

[64, 25, 12, 22, 11]


Pass 1 (i = 1, key = 25)

Sorted part: [64]

[25, 64, 12, 22, 11]


Pass 2 (i = 2, key = 12)

Sorted part: [25, 64]