What is the main advantage of using a segment tree for range queries compared to a simple array traversal?
Think about how segment trees speed up repeated queries over intervals.
Segment trees store precomputed information about segments of the array, allowing queries like sum or minimum over a range to be answered in O(log n) time instead of O(n) by simple traversal.
For an array of size n, what is the maximum number of nodes in its segment tree?
Consider the shape of a full binary tree built on the array.
A segment tree is a binary tree where each node represents a segment. Its size is at most 4 * n to accommodate all segments, especially when n is not a power of two.
Given the array [5, 2, 6, 3, 1, 7] and a segment tree built for range minimum queries, what is the result of querying the range [1, 4] (0-based indices)?
Look for the smallest number between indices 1 and 4 inclusive.
The elements in the range [1,4] are [2, 6, 3, 1]. The minimum is 1.
After updating the value at index 3 in the array, which nodes in the segment tree must be updated?
Consider how the segment tree aggregates values from leaves to root.
When a leaf node is updated, all its ancestor nodes must be updated to reflect the change in their segment values.
Which of the following statements correctly compares segment trees and Fenwick trees (Binary Indexed Trees) for range sum queries?
Think about flexibility and memory usage differences between the two data structures.
Fenwick trees are memory efficient and fast for point updates and prefix sums but struggle with range updates. Segment trees are more flexible, supporting range queries and updates but use more memory.