Dynamic Programming21 sections · 916 units
Open in Course

Knight Probability - Base Cases

Boundaries

1.1. If (r,c)(r, c) is off the board: return 00. The knight has fallen off.

2.2. If k=0k = 0 and (r,c)(r, c) is on the board: return 11. No more moves needed, and you're still on the board. These two cases handle all boundaries. Off-board positions contribute nothing. On-board positions with no moves left contribute certainty. This is where recursion stops. Without it, you get infinite recursion and a stack overflow. Every recursive solution needs at least one base case.