Visual Invariants in Sorting Algorithms




Developed by William Braynen




How to use this applet

To start sorting, press the "Sort" button. The sorting routine can then be paused by pressing the "Pause" button (which the "Sort" button becomes once a sorting routine starts). The sorting routine can be stopped by pressing the "New" button.

To choose a particular sorting algorithm, use the radio buttons underneath the "Sort" button.

To create a new list of 200 random numbers (0 < value < 200), select the "Random" radio button and then press the "New" button.
To create a new randomly shuffled list of 200 numbers, none of which repeat (0 < value < 200), select the "Shuffled" radio button and then press the "New" button.

To change the speed of the sorting routine, use the pull-down menu labeled "Speed"

To see the sorted list in the background, click the "S.S.L." ("Show Sorted List") checkbox in the right bottom corner of the applet.


The graph

On the x-axis:  the position of the item in the list (or the array index:  i )
On the y-axis:  the value of the item in the list (or the array value:  A[i])

 

Concepts stressed in this applet

This applet illustrates the operation of a number of sorting algorithms and the concept of an invariant by using a different color to plot the part of the list affected by the invariant, which is a condition that does not change during a program segment's execution.

Source Code Files