Data Structures & AlgorithmsHardICPC regional · data structures

Problem: What is the time for one point update and one rectangle-sum query in a 2D Fenwick tree on an n x n grid?

  1. A. O(n) for each operation
  2. B. O(1) for the query and O(n) for the update
  3. C. O(log^2 n) for each operation
  4. D. O(log n) for each operation, since 2D adds nothing

Correct answer: C. O(log^2 n) for each operation

Both dimensions are Fenwick-indexed, so each operation touches O(log n) rows and O(log n) columns, giving O(log^2 n) per operation.

More Coding Interview Problems questions

Exams that ask this topic