Wednesday, September 22, 2010

In-place_matrix_transposition

How to do in-place matrix transposition?.

Note, if it is n*n matrix, then we can just do one traversal and swap [i][j] with [j][i].
But what if it is not square matrix?.

1 comment:

  1. Now given 2D array will be stored contiguously in memory. So if access array elements using pointer, then i treat entire 2D as 1D array.

    Assume a[] is 1D array (with pointer), and n is the column length,

    for (j = 0; j2j+1; i--) {
    a[i] = a[i-1];
    }

    a[2j+1] = c;
    }


    Not sure how to do in Java as there is no pointer.

    ReplyDelete