Transpose and symmetry.
Swap rows with columns to flip a matrix across its main diagonal — and use the same idea to check for symmetry.
The transpose of a matrix swaps its rows and columns: element m[r][c] becomes element t[c][r]. Geometrically, it reflects the matrix across the main diagonal.
A matrix is symmetric if it equals its own transpose — that is, m[r][c] == m[c][r] for every r and c. This is a square-matrix concept.
Swap indices when reading or writing.
Transpose flips; symmetry checks the flip is a no-op.
Transpose (works for rectangular matrices)
public static int[][] transpose(int[][] m) {
int rows = m.length;
int cols = m[0].length;
int[][] t = new int[cols][rows];
for (int r = 0; r < rows; r++) {
for (int c = 0; c < cols; c++) {
t[c][r] = m[r][c];
}
}
return t;
}
Notice the result has dimensions cols × rows — the original's columns become the new array's rows.
Symmetric check (square matrices only)
public static boolean isSymmetric(int[][] m) {
int n = m.length;
for (int r = 0; r < n; r++) {
for (int c = r + 1; c < n; c++) {
if (m[r][c] != m[c][r]) return false;
}
}
return true;
}
Only the upper triangle (above the main diagonal) needs to be checked; the lower triangle would just check the same pairs again.
Edge case: rectangular matrices
Symmetry only makes sense for square matrices. If the matrix is rectangular, return false right away.
Transpose vocabulary.
Standard matrix terminology.
- Transpose — matrix with rows and columns swapped.
- Symmetric matrix — equals its own transpose.
- Main diagonal — cells where
r == c; unaffected by transpose. - Upper triangle — cells where
r < c. - Lower triangle — cells where
r > c. - Square matrix — same number of rows and columns.
How transpose and symmetry are tested.
Result-grid dimensions and the upper-triangle trick are common.
- Transpose dimensions.
new int[cols][rows]for anrows × colsinput. - Symmetry restricted to square. Rectangular matrices can never be symmetric.
- Upper triangle only. Saves half the comparisons.
- Index swap. Write
t[c][r] = m[r][c], nott[r][c].
Transpose a 2x3 matrix.
Verify dimensions and contents.
Problem. Transpose:
{{1, 2, 3},
{4, 5, 6}}
Step 1. Input is 2 rows × 3 columns. Result is 3 rows × 2 columns.
Step 2. Apply t[c][r] = m[r][c] for each cell:
- m[0][0] = 1 → t[0][0] = 1
- m[0][1] = 2 → t[1][0] = 2
- m[0][2] = 3 → t[2][0] = 3
- m[1][0] = 4 → t[0][1] = 4
- m[1][1] = 5 → t[1][1] = 5
- m[1][2] = 6 → t[2][1] = 6
Result.
{{1, 4},
{2, 5},
{3, 6}}
Symmetry check. If the input were {1, 2}, {2, 5}, it equals its own transpose {1, 2}, {2, 5} → symmetric. If it were {1, 2}, {3, 5}, m[0][1] = 2 but m[1][0] = 3 → not symmetric.
Transpose and symmetry errors.
Index swaps and dimension confusion are the top traps.
- Wrong result size. Result is
cols × rows, notrows × cols. - Writing
t[r][c]instead oft[c][r]. - Trying to transpose in place on rectangular grids. Impossible without resizing.
- Symmetry checks on rectangular inputs. Always check that the matrix is square first.
- Lower triangle redundancy. Checking both triangles doubles the work.
Transpose and symmetry summary.
The index relationships.
Transpose Reference
AP Quick Reference| Operation | Index relationship | AP Exam Tip |
|---|---|---|
| Transpose write | t[c][r] = m[r][c] |
Swap c and r. |
| Transpose dimensions | cols × rows |
Result shape flips. |
| Symmetry condition | m[r][c] == m[c][r] |
True for all pairs. |
| Symmetry scan range | c > r |
Upper triangle only. |
| Rectangular input | Never symmetric | Check shape first. |
How to master transpose and symmetry.
Index swap is the only trick — practise until it's reflex.
Use the three practice tools below this lesson in order:
- MCQ Practice — for transpose questions, draw the result grid with swapped dimensions and fill it cell by cell.
- Java Lab — implement transpose for rectangular grids and isSymmetric for squares. Test on identity, zero, and known-symmetric matrices.
- FRQ Practice — when a problem hints at reflecting or swapping, reach for the transpose index swap as the core operation.
Practice — attempt these now.
AP-style assessments aligned to this lesson. Time them.