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.

Bubble Sort

An extremely simple sort algorithm with so abysmal performance that this demonstration doesn't show every step.

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