From the course: Python Data Structures and Algorithms
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Code a breadth-first search in Python - Python Tutorial
From the course: Python Data Structures and Algorithms
Code a breadth-first search in Python
- Now the time has come to code Breadth first search in Python. So this is chapter O six O three. And if you open up BFS.PY you'll see there's some template code. Now this is very, very similar to what we had with DFS. So we mentioned in the comments that we're using row column tuples on line five, we have the same imports, almost the same, except instead of the stack, we have queue being imported from queue_ll. And just a point of interest, notice that when we're importing from a module, we don't put .PY at the end of our file. So this is the queue_ll.PY file without the .PY being mentioned, that's how the inputs work. Then we have the same test, exactly the same as we had in DFS at the bottom. The only difference being that we're testing on a different maze. So if you were to go into mazes, you'd see that the maze here is slightly different. Mini maze BFS. I've said it to be the same maze that we looked at in the previous video when we were using the Grit Tracer App. So mini maze…
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)
-
-
-