ProgrammingHard

Which of these statements about in-place transposition is correct?

  1. A. Any R x C matrix can be transposed in place with the same swap loop
  2. B. An n x n matrix can be transposed in place by swapping a[i][j] and a[j][i] for j > i
  3. C. In-place transposition needs an extra row of memory always
  4. D. Transposition in place is impossible for any matrix

Correct answer: B. An n x n matrix can be transposed in place by swapping a[i][j] and a[j][i] for j > i

For a square matrix the swap loop with j > i touches each pair once. A non-square matrix changes shape, so the swap loop does not apply.

More C Programming questions

Exams that ask this topic