Name Best-case Average-case Worst-case Memory Stable
StoogeSort n2.71 n2.71 n2.71 1 no

StoogeSort


Your browser does not support the HTML5 canvas tag.

Java Code

public void stoogeSort(int[] array, int i, int j) {
     int t;
     if (array[ j ] < array[ i ])
          swapKeys( array , i , j );
     if (( j - i + 1 ) >= 3) {
          t = ( j - i + 1 ) / 3;
          stoogeSort( array , i , j - t );
          stoogeSort( array , i + t , j );
          stoogeSort( array , i , j - t );
     }
}
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 20 keys.
The "Sort" button starts to sort the keys with the selected algorithm. Alternatively you can sort 20 random keys fast for a quick impression of how the algorithm works.