A late sale breaks prefix sums
transcript
A shop records takings each hour. Managers ask for totals of stretches. Prefix sums answer in two reads. Then a late sale arrives. So the totals must stay correct.
Here are eight hours of takings. Hours two to five total twenty six. Managers ask this question all day. Adding them one by one is slow for a long day.
Prefix sums store the running totals. Hours two to five are thirty four minus eight. That is two reads and one subtraction. Every question costs the same.
Now add four to hour two. Six of the eight entries change. A change at hour zero rewrites all eight. Rewrites grow with the length of the day.
A day has a hundred thousand hours. A hundred thousand changes cost ten billion rewrites. That is far too slow for a live page. We need both steps near seventeen.
A tree of blocks fixes both. Full breakdown in the lecture.