The Deep Dive (DFS)

MediumAcc. 90.2%
+35 XP 15

The Deep Explorer (DFS)

Depth-First Search (DFS) is like a brave explorer following a single path until they hit a dead end, then backtracking to find the next available trail. It is essential for discovering paths, cycles, and connectivity in complex networks.

The Assignment

Your mission is to explore the deepest reaches of the network. Your function receives an adjacencyList and a startNode.

  1. Use a Recursion or a Stack to travel as deep as possible.
  2. Maintain a Visited Set to track where you have already been.
  3. For the current node:
    • Print its identifier.
    • Mark it as visited.
    • Recursively visit every unvisited neighbor.

01EXAMPLE 1

InputadjList=[[1, 2], [0], [0]]
Output0 1 2

Explanation: Path: 0 -> 1 -> 2.

Constraints

  • Standard recursive DFS.
GraphsAlgorithms
JavaScript
Loading...
1 Hidden

Input Arguments

adjList[[1,2],[0,2],[0,1]]

Expected Output

0
1
2

Click RUN to test your solution