The pseudo-code appears to be wrong. (It's actually possible for the base case to never be encountered if the node depth/limit values skip eachother - being simultaneously increased and decreased in each recursive call.)
The recursive case was written with the limit - 1
so a base case can be reached (instead of "limit", think "remaining").
However, the base case for the limit is if Depth[node] = limit then return cutoff
. Following David Chan's suggestion it should be if 0 = limit then return cutoff
, which would agree with the limit - 1
in the recursive case.
Alternatively, just pass limit
in the recursive case and leave the current base case alone.