Sorting Visualizer

Visualize common sorting algorithms in action.

Algorithm Complexity

bubble Sort

Time (Average)O(n²)
SpaceO(1)

Comparisons

0

Swaps

0

Steps Elapsed

0

Algorithm Source
1function bubbleSort(arr) {
2  const n = arr.length;
3  for (let i = 0; i < n; i++) {
4    for (let j = 0; j < n - i - 1; j++) {
5      if (arr[j] > arr[j + 1]) {
6        // Swap
7        let temp = arr[j];
8        arr[j] = arr[j + 1];
9        arr[j + 1] = temp;
10      }
11    }
12  }
13}