Depth-First Search (DFS) Interactive Tool
Model your graph with an adjacency list, pick a start node, and see the DFS visit order, timestamps, and edge classification. Ideal for studying algorithms, preparing technical interviews, or debugging graph code.
1. Graph input
Format: one node per line, use colon then space-separated neighbors. Example:
B: D
C: D E
D: F
E:
F:
2. DFS results
Visit order
—
| Node | Discovery time (d) | Finish time (f) | Parent |
|---|---|---|---|
| Run DFS to populate | |||
Edge classification (directed)
We classify edges as tree, back, forward, or cross (for directed graphs). For undirected graphs, non-tree edges are typically back edges.
How DFS works
Depth-first search explores a graph “deeply”: from the current node, it visits one unvisited neighbor, then one of its neighbors, and so on, backtracking when no unvisited neighbors remain. This tool follows the classic CLRS-style DFS with discovery and finish timestamps.
DFS(G):
for each vertex u in G.V:
color[u] = WHITE, parent[u] = NIL
time = 0
for each vertex u in G.V:
if color[u] == WHITE:
DFS-Visit(u)
DFS is fundamental in algorithms for:
- Topological sort (on DAGs)
- Detecting cycles
- Finding connected components
- Classifying edges (tree, back, forward, cross)
Time complexity
With an adjacency list, DFS runs in O(V + E), which is optimal for a full traversal.
Directed vs undirected
In directed graphs, edge classification is meaningful (tree/back/forward/cross). In undirected graphs, every non-tree edge is effectively a back edge to an ancestor.
Formula (LaTeX) + variables + units
','\
DFS(G): for each vertex u in G.V: color[u] = WHITE, parent[u] = NIL time = 0 for each vertex u in G.V: if color[u] == WHITE: DFS-Visit(u)
- No variables provided in audit spec.
- NIST — Weights and measures — nist.gov · Accessed 2026-01-19
https://www.nist.gov/pml/weights-and-measures - FTC — Consumer advice — consumer.ftc.gov · Accessed 2026-01-19
https://consumer.ftc.gov/
Last code update: 2026-01-19
- Initial audit spec draft generated from HTML extraction (review required).
- Verify formulas match the calculator engine and convert any text-only formulas to LaTeX.
- Confirm sources are authoritative and relevant to the calculator methodology.