Sorting Algorithms

Visualize and compare different sorting algorithms. Watch how they work step by step and analyze their performance.

Bubble Sort

Bubble Sort is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements and swaps them if they are in the wrong order.

Best: O(n)
Average: O(n²)
Worst: O(n²)
Space: O(1)
Speed50%
Array Size30 elements
Comparisons
0
Swaps
0

How Bubble Sort Works: Bubble Sort is one of the simplest sorting algorithms. It works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order.

  1. Start at the beginning of the array
  2. Compare the first two elements. If the first is greater than the second, swap them
  3. Move to the next pair of elements and repeat the comparison and swap if necessary
  4. Continue until the end of the array
  5. At this point, the largest element has "bubbled up" to the end
  6. Repeat the process for the remaining elements (excluding the already sorted ones)

After each pass through the array, one more element is guaranteed to be in its correct position, starting from the end of the array.