As we discussed earlier, we can undo the process if the subtask doesn't work. Let's try with a labyrinth where we have to find the way from the starting point to the finishing point. Let's suppose we have to find the way from S to F as in the following labyrinth:
# # # # # # # # # S # # # # # # # # # # # # # # # # # # # # # # # # F # # # # # # # # #
To solve this problem, we have to decide the route we need, to find the finishing point. However, we will assume that each choice is good until we prove it's not. The recursion will return a Boolean value to mark whether it's the right way or not. If we choose the wrong way, the call stack unwinds and it will undo the choice. First, we will draw the labyrinth in our code. ...