Fork me on GitHub

Algorithms

This is a demonstration of selected algorithms from the book Introduction to Algorithms by Cormen et. al., implemented in JavaScript by Felix H. Dahlke.

Insertion Sort

A simple sort algorithm, works like most people sort cards on their hand.

Sorry, your browser doesn't support HTML5 Canvas.
function insertionSort(array) {
    for (var i = 1; i < array.length; i++) {
        var key = array[i];
        for (var j = i - 1; j >= 0 && array[j] > key; j--)
            array[j + 1] = array[j];
        array[j + 1] = key;
        update(array);
    }
}