Skip to main contentSkip to solution

The number of passes required by the bubble sort algorithm to sort 'n' elements in the list are________ .

Solution

✅ Correct Option: 1

In each pass of bubble sort, the largest unsorted element moves to its correct position at the end of the list. After n−1n-1 passes, n−1n-1 elements are in place, so the remaining one must be in place too.

So nn elements need n−1n-1 passes.


Option 2: n2n^2 is the time complexity (roughly the number of comparisons), not the number of passes.

Total comparisons in the worst case: (n−1)+(n−2)+⋯+1=n(n−1)2(n-1) + (n-2) + \dots + 1 = \dfrac{n(n-1)}{2}

Pass count and comparison count are different things: passes =n−1= n-1, comparisons ≈n2\approx n^2.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question