Insertion sort

Insertion sort

Insertion sort on arrays

start by taking the first two elements and either keeping or swapping. This is the sorted part of the list now.

Go to next element If bigger, ok next If smaller, scan across sorted part of list to see where it belongs. Move elements up as necessary and insert the element.

Average \(O(n^2)\) for swaps and comparisons.