What is the worst-case behavior (number of comparisons) for bubble sort?

2019

What is the worst-case behavior (number of comparisons) for bubble sort?

  1. A.

    O(1)

  2. B.

    O(n log n)

  3. C.

    O(n)

  4. D.

    O(n2)

Attempted by 118 students.

Show answer & explanation

Correct answer: D

Bubble sort compares adjacent elements repeatedly. In the worst case, it makes a quadratic number of comparisons, so the behavior is O(n^2).

Explore the full course: Coding For Placement