Data Structures & AlgorithmsModerateWipro NLTH · Arrays

What is the minimum number of adjacent swaps needed to sort [3, 1, 2, 5, 4] in ascending order?

  1. A. 2
  2. B. 3
  3. C. 4
  4. D. 5

Correct answer: B. 3

Each adjacent swap removes exactly one inversion; the inversions are (3,1), (3,2) and (5,4), so 3 swaps.

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

Exams that ask this topic