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

How many swaps does bubble sort (adjacent swaps, ascending) make on [27, 39, 17, 5, 21, 29, 48, 12, 41]?

  1. A. 16
  2. B. 18
  3. C. 15
  4. D. 12

Correct answer: C. 15

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

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

Exams that ask this topic