From the course: Python Data Structures and Algorithms
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Visualize breadth-first search in a grid - Python Tutorial
From the course: Python Data Structures and Algorithms
Visualize breadth-first search in a grid
- [Instructor] We are now going to trace the path, of Breadth-first Search for a small sample maze. So the initial configuration is very similar to what we had for Depth-first Search. We have our initial cell marked in blue, and our destination cell marked in green and then down in these text boxes we have our data structure, which in this case is a queue containing just the initial cell. And we also have a list of predecessors currently only containing A which has none as its predecessor because it's the initial cell. So let's begin our algorithm. First of all I dequeue so that means A comes off my queue. And I'm going to mark A in red now to show that it's actually been visited. Then I ask myself is this the goal? Well, it's not the goal. So I have to go into my loop which tells me I have to enqueue undiscovered neighbors, so that means D, that's the only one I can actually access from here. That goes onto my queue. And also I'm going to update the predecessors so D now has…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Understand the breadth-first search algorithm3m 1s
-
(Locked)
Visualize breadth-first search in a grid5m 10s
-
(Locked)
Code a breadth-first search in Python6m 39s
-
(Locked)
Challenge: Trace the path of a breadth-first search30s
-
(Locked)
Solution: Trace the path of a breadth-first search37s
-
(Locked)
-
-
-