AlgoPrecision

Generator Driven

Sorting Visualizer

Generator snapshots drive the bars, controls, and highlighted code from one source of truth.

O(n^2)
42
18
67
29
91
54
36
73
Details
function bubbleSort(input: number[]) {
  const arr = [...input]

  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr.length - i - 1; j++) {
      if (arr[j] > arr[j + 1]) {
        swap(arr[j], arr[j + 1])
      }
    }
    markLastUnsortedItemComplete()
  }
  return arr
}