Data Structures & AlgorithmsModerateProduct Company SDE · data structures
Problem: In a Fenwick tree over n positions, what is the cost of a range-sum query combined with point updates?
- A. O(n) per operation
- B. O(log n) per operation
- C. O(1) per operation
- D. O(n log n) per operation
Correct answer: B. O(log n) per operation
Both prefix queries and point updates touch O(log n) indices, so a range sum is two prefix sums in O(log n).
More Coding Interview Problems questions
- Problem: Which property must a function have for ternary search to find its maximum correctly?
- Problem: Dijkstra with a binary heap on a graph with E = 10^6 edges and V = 10^5 vertices runs in roughly how many elementary operations?
- Problem: Which statement about Hopcroft-Karp is correct?
- Problem: What does the Gale-Shapley algorithm guarantee for stable matching with n men and n women?
- Problem: How many states does a bitmask DP over subsets of n = 15 items have?
- Problem: Which statement about the Floyd-Warshall algorithm's memory usage for V vertices is correct?