ProgrammingModerate
A matrix of 3000 x 3000 cells is read once and each cell is visited a constant number of times. Which complexity bound applies to the whole job?
- A. O(27 x 10^9), which is cubic in the side length
- B. O(9 x 10^6), which is linear in the number of cells
- C. O(3000^4), which is quartic
- D. O(log 9 x 10^6), which is logarithmic
Correct answer: B. O(9 x 10^6), which is linear in the number of cells
The work is proportional to the cell count, 9 x 10^6. Cubic or quartic bounds apply only when each cell is combined with many others.
More C Programming questions
- A recursive merge sort on 10^6 elements makes how many comparisons, roughly?
- Which function call costs O(n) time per call and can be avoided by caching its result in a loop?
- A recurrence T(n) = 2 T(n/2) + n describes which algorithm, with which complexity?
- For a number n up to 10^18 read as a decimal string, what is the number of digits, computed with one pass?
- A program keeps a set of at most 10^5 ints and answers membership queries 10^5 times. Which structure is correct and fast enough?
- Which statement about finding the length of a null-terminated C string is correct?