Concept
DFS follows one path as far as it goes before backing up, using recursion or an explicit stack. It finds connected components, detects cycles, and underlies topological sort and backtracking.
The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.
A few lines that show Depth-first search doing its job.
def count_components(graph, nodes):
seen = set()
def dfs(node):
stack = [node]
while stack:
n = stack.pop()
if n in seen: continue
seen.add(n)
stack.extend(graph[n])
count = 0
for node in nodes:
if node not in seen:
dfs(node); count += 1
return countRecursing on a large graph or grid and hitting the recursion limit. Python's default limit is 1000 frames, so a 100 by 100 grid can crash a recursive DFS. Use an explicit stack.
Your roadmap puts these before Depth-first search, unless you already know them.
Once a session shows you understand Depth-first search, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.
Topics that build on Depth-first search.