Breadth-first search and its uses

In the introductory tutorial, you played with having a character move through a maze to reach a goal. You started by saying that the goal is zero steps away from itself. Then you found all the squares that were one step away from the goal. Then all squares two steps away from the goal. Then three steps, and so on, until you reached the square where the character started. If you kept track of which square at distance kk you came from to get to a square at distance k+1k+1, you could backtrack to find a route from the character to the goal.

Here's the picture that we saw in the introductory tutorial:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy