Overview
A segment tree recursively partitions an array into intervals and stores an aggregate for each interval. Queries combine summaries from O(log n) disjoint nodes, and updates repair summaries on the path to the root.
Maintains aggregate values over intervals by storing summaries in a binary tree.
Compact metadata for implementation and discovery.
A segment tree recursively partitions an array into intervals and stores an aggregate for each interval. Queries combine summaries from O(log n) disjoint nodes, and updates repair summaries on the path to the root.
Quick facts
Runtime and memory behavior at a glance.
Best
O(n)
Average
O(log n)
Worst
O(log n)
Space
O(n)
Show array intervals grouped into a tree of aggregates.
Segment trees are flexible, but their correctness depends on consistent interval conventions.
What each reference supports for this entry.
Data-structures reference for segment trees, interval aggregation, range queries, and update traversal.
Good next jumps from the relationship graph, ranked for useful discovery.
Data Structures · Specialized
Persistent segment trees retain historical versions of segment tree updates.
Compare with thisData Structures · Core
Segment trees handle more general range queries and updates than Fenwick trees.
Compare with thisSegment trees handle more general range queries and updates than Fenwick trees.
Segment trees support updates, while sparse tables are usually static.