Segment Tree
A tree of range summaries that answers “what is the minimum, maximum or sum over this range?” and lets values change, each in about log n steps.
After this lesson you will be able to
- Describe a segment tree as a tree whose node stores the answer (sum, min, max, gcd, …) for a range of the array.
- Build one, apply a point update, and answer a range query, in an iterative bottom-up form.
- Explain which nodes a query takes whole, ignores or opens, and why only about 2 log n nodes are visited.
- Explain lazy propagation and use it for range updates with range sums.
- Choose between a prefix array, Fenwick tree, sparse table and segment tree.
Before you start. Trees (parents, children, recursion on halves) and Prefix Sum. Fenwick Tree is a useful warm-up but not required.