Name Best-case Average-case Worst-case Memory Stable
SelectionSort n2 n2 n2 1 no


Your browser does not support the HTML5 canvas tag.

Java Code

public void selectionSort(int[] array) {
     int minpos;
     for (int i = 0; i < array.length; i++) {
          minpos = i;
          for (int j = i + 1; j < array.length; j++) {
               if (array[ j ] < array[ minpos ])
                    minpos = j;
          swapKeys( array , minpos , i );

public void swapKeys(int[] array, int i, int j) {
     int temp;
     temp = array[ i ];
     array[ i ] = array[ j ];
     array[ j ] = temp;

How to use

Use the textfield to type in a number and add it by either pressing ENTER or by clicking on the "Add" button.
You can also add 10 random numbers at once by clicking on the "10 Random Keys" button. Overall you can add up to 50 keys.
The "Sort" button starts to sort the keys with the selected algorithm. Alternatively you can sort 100 random keys fast for a quick impression of how the algorithm works.