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 - 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…
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)
-
-
-
-
-