9/38
Part 2 of 7 · RecursionLearn and do
One walk stores every subtree's answer
Often you want the size of every region, not one. Calling size once per region is correct and wasteful: the call for Portugal redoes the work already done for Lisbon District. On a chain, where each region holds exactly one region, the waste is a triangle:
A chain of 400 regions. Call size once for each region. How many calls in all?
Pick an answer above to see the rest