Skip to content
doubtly

2 answers

Answer: (a) \(\dfrac{n(n-1)}{2}\)

Bubble sort compares adjacent pairs. In the first pass it makes \(n-1\) comparisons, in the second \(n-2\), and so on until 1 comparison in the last pass:

\[(n-1) + (n-2) + \dots + 1 = \frac{n(n-1)}{2}.\]

That is why bubble sort is \(O(n^{2})\). (An optimised version stops early if a pass makes no swaps, but the standard count asked in exams is \(n(n-1)/2\).)

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.