Data Structures & AlgorithmsModerateGATE CS · competitive programming

What is the minimum number of swaps needed to transpose a 6×6 matrix in place?

  1. A. 30
  2. B. 15
  3. C. 36
  4. D. 12

Correct answer: B. 15

Only the pairs with i < j need one swap each, giving 6·5/2 = 15. Swapping all 36 cells would swap every pair twice and cancel out.

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

Exams that ask this topic