Bubble Sort

Overview

Bubble sort works by iterating downward through an array, swapping larger elements upward as needed.

Property Value
Best Case Ω(n2)
Worst Case O(n2)
Avg. Case O(n2)
Aux. Memory O(1)
Stable Yes
Adaptive Yes
Visualization bubble-sort.gif

Loop Invariant

Bubble sort has loop invariant P given by

A[0:i-1] is a sorted array of the i least elements of A.

Powered by Forestry.md