Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: What is the time complexity of a segment tree's range-query and point-update operations on an array of size n?

  1. A. O(1) for both
  2. B. O(log n) for both
  3. C. O(n) for both
  4. D. O(log n) for update but O(n) for query

Correct answer: B. O(log n) for both

A segment tree has height O(log n); both a point update and a range query touch only O(log n) nodes along root-to-leaf paths (or a small set of disjoint segments), so both run in O(log n).

More Coding Interview Problems questions

Exams that ask this topic