The best answer is enough so here I m just posting about the difference between tree depth & recursion depth
1. Tree/Graph Depth
When we say a node is at depth 4 from root:
A → B → C → D → E
Depth of E = 4 edges
because
depth=#edges from root
2. Recursion Depth
Suppose DFS does:
DFS(A)
DFS(B)
DFS(C)
DFS(D)
DFS(E)
At the deepest point, stack contains:
A
B
C
D
E
That's 5 function calls.
So recursion depth = 5, not 4.
Relationship
For a simple chain:
A → B → C → D → E
- Number of edges = 4
- Number of vertices = 5
- Recursion depth = 5
Hence:
Recursion Depth=Path Length (edges)+1