Name Best-case Average-case Worst-case Memory Stable
RadixSort (LSD) - n × (k/d) n × (k/d) n yes

RadixSort


Your browser does not support the HTML5 canvas tag.

Java Code

// for arrays with integers from 0 to 99
public void radixSort(int[] array) {
     int counter = 0;
     LinkedList<LinkedList<Integer>> allBuckets = new LinkedList<LinkedList<Integer>>();

     for (int i = 0; i < 10; i++) {
          allBuckets.addLast( new LinkedList<Integer>() );
     }

     for (int i = 0; i < array.length; i++) {
          int j = array[ i ] % 10;
          allBuckets.get( j ).addLast( array[ i ] );
     }

     for (int i = 0; i < 10; i++){
          while ( !allBuckets.get( i ).isEmpty() ) {
               array[ counter ] = allBuckets.get( i ).pollFirst();
               counter++;
          }
     }

     for (int i = 0; i < array.length; i++) {
          int j = ( (int ) ( array[ i ] / 10 ) ) % 10;
          allBuckets.get( j ).addLast( array[ i ] );
     }

     counter = 0;

     for (int i = 0; i < 10; i++) {
          for (int j = 0; j < allBuckets.get( i ).size(); j++) {
               array[ counter ] = allBuckets.get( i ).get( j );
               counter++;
          }
     }
}
            

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.