Interactive Data Structure Visualizations
Quadratic Sorts

Sorting algorithms are fundamental to computer science. Sorted data has the important advantage that it can then be efficiently searched, using a binary search. The quadratic sorting algorithms, those whose efficiency is O(n2), are important because, although they are not the most efficient algorithms, they are conceptually the simplest.

Three sorting algorithms are implemented in this segment. The swap operation is fundamental to both the bubble sort and the selection sort. In the bubble sort, pairs of adjacent elements are swapped, if they are out of order. After one sweep of the data from right to left, the smallest element is in the left-most position. Subsequent sweeps move the remaining values to their proper position. In the selection sort, the smallest element is swapped with the element in the first position. Then, the smallest of the remaining elements is swapped with the second element and so on.

The fundamental operation of the insertion sort is a right rotation. In the insertion sort each element is examined in turn and inserted into its proper position among the already sorted elements. The insertion sort is one we commonly use, to sort checks or to assemble a hand of cards in a card game.