Insertion Sort works the way we sort playing cards. Each iteration removes an element from the input data and inserts it into the correct position. O(n 2) average and worst. Insertion sort is the best of simple sorting. For random data this algorithm runs twice as fast as the bubble sort and faster than selection sort.


Source code

Java

Javascript

Python

Doodle

insertion sort doodle

Download Java, JavaScript and Python code
Insertion sort animated