Graph Depth-First Traversal

Visit every node reachable from a start node in iterative depth-first preorder over directed edges, descending into the smallest-numbered neighbor first and reporting each node's depth.

Description

Traverse all reachable nodes in deterministic iterative depth-first preorder and report traversal depth.

Graph Depth-First Traversal traverse all reachable nodes in deterministic iterative depth-first preorder and report traversal depth.

Use this for structural exploration, reachability, preorder processing, and examples where following a branch before siblings is desirable.

When to use Graph Depth-First Traversal

Use this for structural exploration, reachability, preorder processing, and examples where following a branch before siblings is desirable.

How it works

An explicit stack visits the start and descends through normalized neighbors before backtracking. A visited set prevents cycles from looping.

Interpreting the result

Keep the input units, direction conventions, encoding, and ordering rules visible when reusing the result. Preserve the full returned value for downstream calculations and round only for presentation.

Assumptions and limitations

Reported depth belongs to the chosen DFS tree and is not generally a shortest-path distance. Only reachable nodes appear, edges are directed, and neighbor ordering affects preorder.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies