The calls go deep first, and each answer is built on the way back up
The order the calls run in gives depth-first search its name.
Predict
size("Portugal") calls size("Lisbon District") first. Which call is the first to return?
Here is size("Portugal"), one call per line, each under the call that made it:
size("Portugal"), call by call
Portugalreturns 7 = 1 + 4 + 2, last of all
Lisbon Districtreturns 4 = 1 + 1 + 1 + 1
Lisbonreturns 1, the first to return
Sintrareturns 1
Cascaisreturns 1
Porto Districtreturns 2 = 1 + 1
Portoreturns 1
The calls run from the top down. A call returns only after every call under it.
The calls go down one branch as far as it goes before trying the next. That's depth-first.
No call can return until every call under it has. So a region's answer is built on the way back up, from answers already finished below it. Lisbon District's 4 waits for Lisbon, Sintra and Cascais.
Python keeps the calls that haven't returned on its call stack: in the figure, the path from Portugal down to the current call. There are never more of them than the regions on that path. So the memory is O(h), where h is the tree's height, and the time is O(n), one call per region.