DFS DFS
Depth first search (
DFS
) is one of the main algorithms on graphs. The algorithm runs in
O(N + M)
.
Algorithm
To begin with, we start from the top, consider the children of this top, and if we have never entered them, then we start
DFS
from them.