Example: 1,3,5,7,9,11 (max 16 elements for best visualization)
Range Query
Update Value / Range
Lazy Propagation (Range Update)
Node Details
Click on any node in the tree to view its details here.
Operation Log
No operations yet. Build a tree to get started.
Segment Tree Visualization
Build a tree to see the visualization here.
Segment Tree Visualizer Help
What is a Segment Tree?
A segment tree is a data structure that allows efficient range queries and updates on an array.
It can answer range sum, minimum, maximum, product, and other aggregate queries in O(log n) time.
What is Lazy Propagation?
Lazy propagation is an optimization technique for segment trees that allows for efficient
range updates (e.g., adding a value to all elements within a range).
Instead of updating all individual leaf nodes in the range, it "lazily" marks internal
nodes with pending updates and pushes these updates down to children only when necessary
(i.e., when querying or updating a segment that overlaps with the lazy node's range).
How to Use This Visualizer
Build Tree: Enter an array of numbers (comma-separated) and click "Build Tree"
Range Query: Enter a start and end index to query the sum/min/max/product in that range
Point Update: Change a value at a specific index and see the tree update
Range Update (Lazy): Add a value to all elements in a given range using lazy propagation.
Step-by-Step: Use the step-by-step mode to see how queries and updates work
Node Details: Click on any node to see its details