ProgrammingModerate

A square matrix is symmetric when a[i][j] equals a[j][i]. What is the time needed to test an n x n matrix for symmetry in C?

  1. A. About n comparisons, since only the diagonal matters
  2. B. About n^3 comparisons
  3. C. About n^2 / 2 comparisons, since each pair with j > i is compared once
  4. D. About n^4 comparisons, since each row is compared with every column

Correct answer: C. About n^2 / 2 comparisons, since each pair with j > i is compared once

Each unordered pair (i, j) with i < j is checked once, which is about n^2 / 2 comparisons.

More C Programming questions

Exams that ask this topic