AiTechWorlds
AiTechWorlds
Watch Depth-First Search dive deep and backtrack with a live stack, synced pseudocode, and an interactive graph.
def dfs(adj, u, vis):
vis.add(u)
for v in adj[u]:
if v not in vis:
dfs(adj, v, vis)DFS explores as far as possible along each branch before backtracking, using a stack (or recursion). It underlies cycle detection, topological sort, and SCC algorithms.
| Time | O(V + E) |
| Space | O(V) |
| Graph | Undirected, unweighted |
The DFS Visualizer animates how Depth-First Search works: starting from a source node, it explores as far as possible along each branch before backtracking, using a stack or recursion. DFS runs in O(V + E) time, uses O(V) space, and underlies cycle detection, topological sort, and strongly connected components.
Generate a graph
Click New Graph or set the node-count slider to create a random graph.
Play the animation
Press Play to watch the stack drive deep exploration and backtracking.
Step and scrub
Use Step Forward/Back or the timeline to inspect each push and pop.
Read the synced code
The highlighted pseudocode line tracks the traversal; switch tabs for C++, Java, Python, or JavaScript.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.