Data Structures & AlgorithmsModerateProduct Company SDE · data structures

Problem: In a segment tree with lazy propagation, what is the cost of one range-add update on an array of length n?

  1. A. O(n), since lazy tags must reach every leaf
  2. B. O(log n), because only O(log n) nodes are visited and tagged
  3. C. O(sqrt n), using block decomposition
  4. D. O(1), since tags are never pushed

Correct answer: B. O(log n), because only O(log n) nodes are visited and tagged

A range update touches O(log n) canonical nodes, each marked with a lazy tag that is pushed down only when needed. Pushing to every leaf would be O(n) and is not required.

More Coding Interview Problems questions

Exams that ask this topic