• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 08, 2022 |5.6K Views

Lazy Propagation in Segment Tree

Description
Discussion

Segment tree is introduced in previous post with an example of range sum problem. We have used the same “Sum of given Range” problem to explain Lazy propagation.


In the previous post, update function was called to update only a single value in array. Please note that a single value update in array may cause multiple updates in Segment Tree as there may be many segment tree nodes that have a single array element in their ranges.


Below is simple logic used in previous post. 
1) Start with root of segment tree. 
2) If array index to be updated is not in current node’s range, then return 
3) Else update current node and recur for children.

Lazy Propagation in Segment Tree : https://www.geeksforgeeks.org/lazy-propagation-in-segment-tree/