- Home
- /
- General
- /
- Miscellaneous
- /
- Depth-First Search (DFS) Interactive Tool
Depth-First Search (DFS) Interactive Tool
Interactive depth-first search (DFS) tool. Paste an adjacency list, choose directed or undirected, select a start node, and see visit order, discovery/finish times, and DFS tree edges.
Graph Input
Format: Node: neighbor1 neighbor2. Blank lines are ignored.
How to Use This Tool
Model your graph as an adjacency list, pick whether the edges are directed, choose a starting node (optional), and click Run DFS. This hero view summarizes the visit order, metadata, and a tabular view of discovery/finish timestamps.
1. Graph input
Write one node per line, use a colon after the node, then space-separated neighbors. Blank lines are ignored and neighbors are added automatically for undirected graphs.
B: D
C: D E
D: F
E:
F:
- Use simple labels (A, B, C or 1, 2, 3) to keep the visit order readable.
- The start node is optional; if omitted, the algorithm visits nodes in alphabetical order after the current component is exhausted.
- Check the Directed graph box when edge direction matters; leave it unchecked for undirected traversal.
2. DFS results
The hero result box shows the full visit order. KPI rows highlight node/edge counts, how many components were explored, and which node you seeded first.
The traversal table lists discovery and finish timestamps per node, and the edge inspection pane (below) classifies each edge as tree/back/forward/cross for directed graphs or tree/back for undirected graphs.
Methodology
DFS explores a graph deeply by visiting unvisited neighbors until a dead end, then backtracking. This implementation emulates the CLRS-style recursive DFS, tracking discovery/finish timestamps, parents, and edge classification. The pseudo-code lives under the Formulas section.
- Time complexity is O(V + E) with an adjacency list, which is optimal for a full traversal.
- In directed graphs we report tree, back, forward, and cross edges. In undirected graphs every non-tree edge is treated as a back edge to avoid duplicates.
- The component counter increments every time DFS starts from a white node, so you can see how many disconnected pieces the graph has.
Tips
Keep node labels concise (A, B, C or 1, 2, 3). The parser ignores blank lines and trims whitespace, so reformatting is quick. If the start node is missing, DFS will still traverse all nodes in alphabetical order.
Related graph tools
FAQs
What is depth-first search (DFS)? DFS explores as far as possible along each branch before backtracking; typical implementations use recursion or an explicit stack.
What is DFS used for? It powers topological sorting, cycle detection, connected components, edge classification, and spanning tree construction.
What is the time complexity of DFS? It runs in O(V + E) time using an adjacency list.