Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

How many swaps does bubble sort (adjacent swaps, ascending) make on [10, 24, 35, 46, 54, 16, 12, 2, 43]?

  1. A. 19
  2. B. 17
  3. C. 18
  4. D. 22

Correct answer: C. 18

Each adjacent swap removes exactly one inversion, so swaps = number of inversions = 18.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic