Segment Trees & Fenwick Trees
Data Structures & Algorithms · Advanced Structures · Master · 30 min
Answer range-sum (or min / max) queries while values keep changing, both in O(log n), with a segment tree and with the tiny Fenwick tree built on lowbit.
This lesson is part of TuringPath Pro. See plans.
What you will learn
- The problem: range queries while the data changes
- Segment tree: a tree of range sums
- Querying: three cases at every node
- Fenwick tree: the same speed in ten lines
- Which one should I use?
More in Advanced Structures
Previous: Union-Find (Disjoint Sets) · Next: B-Trees & Skip Lists: How Databases Index