Understand how different sorting algorithms work through interactive visualizations
Simple comparison-based algorithm
Divide and conquer approach
Efficient partitioning algorithm
Uses binary heap data structure
Builds final sorted array one item at a time
Comparing elements at positions 2 and 3. Since 40 > 28, we swap them.
for i = 0 to n-1:
for j = 0 to n-i-2:
if array[j] > array[j+1]:
swap(array[j], array[j+1])
In the worst case (reverse sorted array), bubble sort requires \( n-1 \) passes, with the \( i^{th} \) pass making \( n-i \) comparisons. The total number of comparisons is: