Depth-prioritized traversal useful for connectivity and structure discovery.
Easy Explanation
DFS explores one path deeply before backtracking, which is useful for full traversal and structure discovery.
Renderer Mode
`Simple` uses abstract, short-form-friendly visuals. `Advanced` keeps the current detailed view.
Grid
n/a
Visited
0
Depth
n/a
Result
Searching
Safe mode: choose a tool to edit the grid.
Press Play or Step to start execution.
function dfs(graph, start, target):
stack <- [start]
visited <- { start }
parent[start] <- none
while stack is not empty:
node <- pop(stack)
if node == target:
return reconstruct_path(parent, target)
for neighbor in neighbors(node):
if neighbor not in visited:
visited.add(neighbor)
parent[neighbor] <- node
push(stack, neighbor)
return no path