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?
- A. O(1) for both
- B. O(log n) for both
- C. O(n) for both
- 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
- Problem: Finding the median of two sorted arrays of sizes m and n can be done faster than merging them. What is the best known time…
- Problem: Which statement about the backtracking solution to generating all subsets of an n-element set is correct?
- Problem: Generating all permutations of an n-element array via backtracking takes how much time, and why?
- Problem: In the N-Queens backtracking search, what pruning technique keeps the search from degenerating into a full O(N^N) brute force?
- Problem: Which best explains why a monotonic stack is the standard technique for the 'next greater element' problem, giving O(n) overall…
- Problem: A sliding window maximum over an array of size n with window size k is computed with a monotonic deque. What is its time…