AlgoScope

DFS Iterative

Explicit stack of vertices. Avoids recursion depth limits.

Graph traversal, algorithm, intermediateAlso called Stack-based DFS
4 is popped and skipped, already visited.011224334655u
4 is popped and skipped, already visited.011224334655u

BFS and DFS: Depth-first from 0

Step, step 8 of 10

Pop 4, but it was already visited by another route. Discard it.

How bfs and dfs works

Cost

Best
O(V + E)
Average
O(V + E)
Worst
O(V + E)
Space
O(V)

A variant of

Taught by the same lesson

BFS and DFS covers these too, in the same run.