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 depth-first search on a grid - Python Tutorial
From the course: Python Data Structures and Algorithms
Visualize depth-first search on a grid
- [Instructor] Here is the depth-first search algorithm, we will soon be coding in Python written basically in English or pseudocode, so at the top of the slide, we have the two data structures we will use in the algorithm. So we have a stack containing just a start position and we have a dictionary containing the predecessors of discovered cells. If you're not familiar with dictionaries, you can just think of them as collections of key value pairs, much like an actual dictionary contains words as keys and definitions as values or a phone book contains the names as keys and phone numbers as values. So here, we have start position is the key and the value for that key is none, because there's no predecessor to the initial position. Next we have the actual algorithm. Step one is we pop the stack. That means we take the top item of the stack, which in our implementation is actually the right hand end of our list, but think of it as a top. And we ask ourselves, is this the goal? And if it…
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 depth-first search algorithm3m 28s
-
(Locked)
Visualize depth-first search on a grid5m 21s
-
(Locked)
Use the Grid Tracer app2m 35s
-
(Locked)
Code a depth-first search in Python12m 10s
-
(Locked)
Challenge: Trace the path of a depth-first search44s
-
(Locked)
Solution: Trace the path of a depth-first search34s
-
(Locked)
-
-
-
-
-