Segment Tree Visualizer
Build a range-sum segment tree, inspect full-cover and no-overlap query nodes, and preview the path changed by a point update.
Segment tree input
The first 16 whole numbers are used so the tree remains readable.
Range query
Point update
Step controls
Step 1 of 11: Start range sum query [2, 6] at the root.
Tree diagram
Start range sum query [2, 6] at the root.
Array view
Query summary
Trace
What is a Segment Tree Visualizer?
A segment tree visualizer shows how an array is split into nested ranges so range queries and point updates can be answered quickly.
This tool builds a sum segment tree. Every node stores a range [left, right] and the sum for that range. During a query, fully covered nodes are taken, non-overlapping nodes are skipped, and partially overlapping nodes are split.
For the full cluster of related pages, browse the Data Structure Visualizers hub.
How to use this segment tree visualizer
- Paste an array of whole numbers.
- Choose the left and right indexes for a range sum query.
- Run the query to inspect full-cover, partial-overlap, and no-overlap decisions.
- Choose an index and a new value to preview a point update.
- Apply the update when you want to rebuild the tree from the changed array.
Segment tree complexity
A segment tree uses O(n) space and builds in O(n) time. A range query visits only the branches needed to cover the requested interval, which is why range queries are O(log n) for many common operations. A point update also touches one root-to-leaf path, so it runs in O(log n).
If your array never changes, compare this with the Prefix Sum Visualizer. If your array changes often, compare this page with the Fenwick Tree Visualizer.
For static range minimum and maximum queries, compare this page with the Sparse Table Visualizer.