A node holds a summary
transcript
A hundred thousand values. A range sum is asked often. And values change in between. Prefix sums break. What now?
There may be a hundred thousand changes. Each one rebuilds a hundred thousand sums. That is ten billion steps in all. Far too slow.
A node covers a range of positions. It stores a summary of that range. Two halves merge into their parent.
Four leaves hold five, three, eight, six. Change the third leaf to one. Only its parent and the root change. The root becomes fifteen.
An update fixes one path of the tree. A query takes at most two nodes per level. Both cost about seventeen steps for a hundred thousand values.
The tree has two n nodes in all. An update touches one path. Memory is a plain array.
The node decides the problem. Sum, minimum, maximum, or a tag. Then every operation is cheap. Ten billion becomes seventeen. Full breakdown in the lecture.