0

I am tasked with solving a maze using the method of backtracking and recursion. This is more of a conceptual question about this concept.

How is the backtracking call ever reached? From all the examples I have seen it looks as though recursion is always called immediately before the backtracking step, so that backtracking can not be reached. Can anyone explain to me how the backtracking step is reached?

1 Answer 1

1

Backtracking happens when the recursion returns. For example, if you are at location A, and there are two neighboring locations, B and C. You could make a recursive call on B. When it has finished exploring that part of the maze, it will return (ie, backtrack) to the call at location A, which will then make a new recursive call on location C.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.