Algorithms

See how algorithms work, control each step and explore their properties.

Insertion sort

Take the next value and insert it into the sorted prefix. Move larger neighbors one position to the right until there is a place for the key.

Open the visualization →

Bubble sort

Compare adjacent values from left to right and swap them when the left one is larger. Each pass moves the largest remaining value to the end of the unsorted region.

Open the visualization →

Selection sort

Find the smallest value in the remaining region and swap it into the next position. Repeat until every value is in its final position.

Open the visualization →

Merge sort

Merge sort divides an array into halves until each part contains at most one element. It then merges sorted parts, choosing the smaller of their first remaining elements. Follow the main array and the buffer in the player below.

Open the visualization →