Practice Discrete Math

Algorithms / Segment Tree Lazy Propagation

Least You Need to Know: Lazy Propagation for Range Updates and Range Queries

Lazy propagation lets a segment tree postpone pushing range updates into children until that detail is actually needed. The main idea is to keep a pending tag that says, in effect, 'this whole interval has already been updated even if the children are not individually refreshed yet.'

جو کم از کم جاننا ضروری ہے

اہم علامتیں

lazy[node] pending update still to be propagated to children
push transfer a pending tag to child nodes before deeper recursion
4n common safe array size for tree storage in interviews

مختصر حل شدہ مثال

  • Suppose you add 5 to every element in a query range.
  • If a node interval is fully covered, increase its stored aggregate and record a lazy tag instead of updating every descendant immediately.
  • Later, if a partial-overlap query needs the children, push that tag down first.
  • This deferral keeps both range updates and queries efficient.

عام غلطیاں

اس قسم کے سوال کو کیسے پہچانیں

Next recommended lesson

Continue through this topic with Least You Need to Know: Segment Trees, Range Queries, and Overlap Cases.

Least You Need to Know: Segment Trees, Range Queries, and Overlap Cases

Related lessons

Keep going with nearby lessons in the same topic.

More ways to explore

مشق شروع کریں