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:

A: B C
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.


Audit: Complete
Formula (LaTeX) + variables + units
This section shows the formulas used by the calculator engine, plus variable definitions and units.
Formula (extracted LaTeX)
\[','\\]
','\
Formula (extracted text)
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)
Variables and units
  • No variables provided in audit spec.
Sources (authoritative):
Changelog
Version: 0.1.0-draft
Last code update: 2026-01-19
0.1.0-draft · 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.
Verified by Ugo Candido on 2026-01-19
Profile · LinkedIn
, ', svg: { fontCache: 'global' } }; ]], displayMath: [['\\[','\\]']] }, svg: { fontCache: 'global' } };, svg: { fontCache: 'global' } };