DFS: What the Call Stack Is Really Doing
Save My Interview
0:00 / 0:00
DFS: What the Call Stack Is Really Doing
2 просмотра · 9 дн. назад
Save My Interview
11 подписчиков
2 просмотра · 9 дн. назад
Depth-first search commits to a path and plunges as deep as it can before
backtracking — the opposite of BFS. This episode animates the stack growing on
the way down and unwinding on the way back. (Graph series, part 3 of 5.)
• The DFS idea: go deep before wide, backtrack at dead ends
• A color-coded traversal: watch the stack fill, then unwind
• The tiny recursive Python implementation, highlighted line by line
• Why recursion IS the stack — and the iterative alternative
• What DFS unlocks: components, cycle detection, topological sort, flood fill
• Complexity O(V + E), and the call-stack-overflow gotcha on deep graphs
Chapters:
0:00 Intro
0:22 The DFS idea
0:46 DFS traversal (animated)
1:40 DFS in Python (recursive)
2:15 What DFS unlocks
2:41 Complexity & gotchas
3:13 Recap — and Dijkstra next
#DFS #Graphs #Algorithms #Python #Recursion #InterviewPrep #ComputerScience