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

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…

Contents