DSA
intermediate
Depth-First Search (DFS)
Explore graphs by going deep! Unlike BFS, DFS dives into the graph structure. Essential for detecting cycles, topological sort, and maze solving.
Depth-First Search (DFS)
⏱ O(V + E)
💾 O(V)
Ready
Speed:50%
0
1
2
3
4
5
6
Recursion Call Stack (LIFO)
Empty Stack
Stack grows up, top element is current function call
Initialize DFS: start from node 0
Step: 1/24Visited: 0 nodesStack depth: 0
Current
Visited
Exploring
Unvisited
Go deep first
Sequence
Graph: A → B, C · B → D, E · C → F. Visiting neighbours alphabetically, order the nodes as DFS from A visits them.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
- 1Drop a step here
- 2Drop a step here
- 3Drop a step here
- 4Drop a step here
- 5Drop a step here
- 6Drop a step here
6 pieces left to place
Test your knowledge
20 questions
Question 1 of 20
Score: 0
What data structure is implicitly used in recursive DFS?
Write the code
Runs your solution
Number of Islands
javascript
When to reach for this
- Find **Connected Components**
- Detect Cycles in a Graph
- Maze solving / Path existence
- Topological Sorting (DFS based)
Interview Questions
Amazon
Meta
Bloomberg
Meta
LinkedIn
Microsoft
Uber
Google
Airbnb
Amazon
LinkedIn
Bloomberg
Microsoft
Netflix
Google
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required