ProgrammingModerate

A rectangular table with R rows and C columns is traversed in a loop that touches each cell once in row-major order. Which total cost is correct?

  1. A. O(R + C), since only the borders are visited
  2. B. O(R x C), linear in the number of cells
  3. C. O(R^2 x C^2), since each cell is compared with all others
  4. D. O(log(R x C)), since the table is indexed

Correct answer: B. O(R x C), linear in the number of cells

A full traversal touches every cell once, so the cost is proportional to the number of cells.

More C Programming questions

Exams that ask this topic