ProgrammingModerate

A counting pass over an array of 10^7 values, each in [0, 9], uses 10 counters. Which statement is correct?

  1. A. It needs 10^7 counters, one per value
  2. B. One pass with 10 counters is O(n), which is fast enough in C
  3. C. It must sort the values first, which is O(n^2)
  4. D. It is impossible because the counters are not enough

Correct answer: B. One pass with 10 counters is O(n), which is fast enough in C

Each value increments one of the 10 counters, so a single pass gives the answer in O(n) time and O(1) memory.

More C Programming questions

Exams that ask this topic