Segment trees are powerful but verbose. For many problems, you only need prefix queries (sum of elements to ), not arbitrary range queries.
Fenwick Trees (also called Binary Indexed Trees or BITs) provide: - prefix sum queries - point updates - Only extra space (not like segment trees) - About 10 lines of code The tradeoff: Fenwick Trees directly support only prefix queries.
For range , compute . For range minimum queries, Fenwick Trees don't work directly. In this section, I'll teach you how Fenwick Trees use bit manipulation to achieve logarithmic operations, and when to choose them over segment trees.