DFS explores a graph by going as deep as possible along each branch before backtracking. It uses a stack (often the call stack via recursion) and visits a full path before exploring alternatives.
The idea
From a node, recurse into an unvisited neighbor, and keep going deep; when stuck, back up and try another branch.
Example
python
():
visited :
visited = ()
visited.add(node)
order = [node]
nbr graph[node]:
nbr visited:
order += dfs(graph, nbr, visited)
order
graph = {: [, ], : [], : [], : []}
dfs(graph, )
