DFS Iterative
Explicit stack of vertices. Avoids recursion depth limits.
BFS and DFS: Depth-first from 0
Pop 4, but it was already visited by another route. Discard it.
Cost
- Best
- O(V + E)
- Average
- O(V + E)
- Worst
- O(V + E)
- Space
- O(V)
Before this
Related
A variant of
Taught by the same lesson
BFS and DFS covers these too, in the same run.