cifrivo.

Computer science Algorithms At your own pace

Understand algorithms.
One step at a time.

Watch the data change, understand each decision and try what you would do.

Insertion

Put each value where it belongs within the part that is already sorted.

List of 8 values
ComparingMovesSorted part

The numbers below are positions, starting at 0. Letters distinguish equal values.

The first position already forms a sorted part. The next value must be placed within it, like a card in your hand.

0 comparisons0 swapsWe count operations, not animation time.
Show pseudocode The active line follows the step
  1. for i = 1 … n − 1:
  2. j = i
  3. while j > 0:
  4. if a[j − 1] ≤ a[j]: stop
  5. swap(a[j − 1], a[j])
  6. j = j − 1
  7. // a[0 … i] is sorted

The pseudocode describes the rule. Visual steps also include moments to highlight and explain.

Customize the data You can also repeat values

3 to 12 integers from 1 to 99. Separate them with commas or spaces.

Compare all three on this listCounters for the complete run
Same 8 initial values, different algorithms.
AlgorithmComparisonsSwaps
Insertion2218
Selection286
Bubble2718

Try a sorted or reversed list and see what changes. The selector keeps the same list when switching sorting algorithms.

Go step by step. Then try an already sorted list.