From the course: Python Data Structures and Algorithms

Unlock the full course today

Join today to access over 23,400 courses taught by industry experts.

Code a depth-first search in Python

Code a depth-first search in Python - Python Tutorial

From the course: Python Data Structures and Algorithms

Code a depth-first search in Python

- [Instructor] We are now going to code out a version of depth-first search in Python. Our implementation makes use of some helper functions and values that we've provided in a separate file and which we will import into our DFS file. Let's briefly look at helper functions dot py. So, this is chapter 04_04. So we'll go into that folder and have a look at helpers.py. So what have we got here? We got offsets. These are just quick ways of referencing relative positions within our maze. So, if you think in terms of the row and column coordinates, going right means going zero up and down, but one to the right. And going left means going zero up or down, but going negative one to the right, which is the same as going one to the left. And then going up means decreasing the row number, but leaving the column number constant. And going down means increasing the row number, but leaving the column number constant. And then we have exactly the same read_maze function, which we looked at earlier…

Contents