Data Structures & AlgorithmsModerateCodeforces Div2 C · complexity estimate

Problem: For n = 10^5 elements and q = 10^5 queries, a sqrt-decomposition answers each query in O(sqrt n). Roughly how many elementary operations does this take in total?

  1. A. About 10^10
  2. B. About 10^5
  3. C. About 3 * 10^7
  4. D. About 2 * 10^5 * log(10^5)

Correct answer: C. About 3 * 10^7

sqrt(10^5) is about 316, and 10^5 queries times 316 gives about 3.2 * 10^7 operations, which runs comfortably. The last option describes a segment tree, not sqrt decomposition.

More Coding Interview Problems questions

Exams that ask this topic