SortViz

Interactive Sorting Algorithm Visualization

Controls

5 15 30
Fast Medium Slow

Algorithm Info

Bubble Sort: Compares adjacent elements and swaps them if in wrong order.

Time: O(n²) Space: O(1)

Visualization

0
0
0ms

Legend

Normal
Active
Comparing
Sorted
Pivot

Algorithm Details

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. The pass through the list is repeated until the list is sorted.

The algorithm gets its name from the way smaller elements "bubble" to the top of the list. While it's simple to understand and implement, it's not efficient for large datasets with its average and worst-case time complexity of O(n²).

Complexity Analysis

Time Complexity
  • Best: O(n) - When array is already sorted
  • Average: O(n²) - For random data
  • Worst: O(n²) - When array is reverse sorted
Space Complexity
  • O(1) - Sorts in place, no additional space needed