Skip to main contentSkip to solution

How many comparisons are required to sort the list [8,7,6,5,4] using bubble sort?

Solution

✅ Correct Option: 2

Bubble sort makes n−1n-1 comparisons in the first pass, n−2n-2 in the second, and so on down to 1. The total is n(n−1)2\dfrac{n(n-1)}{2}.

For n=5n = 5, the passes make 4+3+2+14 + 3 + 2 + 1 comparisons.

The list is in reverse order, so every pass still swaps elements and no pass can be skipped.

5×42=10\dfrac{5 \times 4}{2} = \boxed{10}

Keyboard Shortcuts

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