AlgoBazaAlgoBaza
Back to algorithms

Depth-First Search (DFS)

A graph traversal algorithm that explores as far as possible along each branch before backtracking.

Sredni
O(V + E)O(V)OIJOI
Select programming language
Choose the language to see the DFS implementation.
Select example
Small, Medium, and Large examples show recursion code generation. Very large shows only the call stack.

DFS (Python): Small graph (4 vertices)

1/0
1.0x