When you call a function in Python, it gets added to a call stack.
Imagine you're unpacking boxes, and each box has another box inside:
π§ This is Last In, First Out (LIFO) β like a stack.
Letβs use a very small tree to understand it fully:
markdown
CopyEdit
1
/ \\
2 3
Now letβs run your function dfs() on this tree.
python
CopyEdit
dfs(1)
βββ dfs(2)
β βββ dfs(None) β 0
β βββ dfs(None) β 0
β return 1 + max(0, 0) = 1
βββ dfs(3)
β βββ dfs(None) β 0
β βββ dfs(None) β 0
β return 1 + max(0, 0) = 1
return 1 + max(1, 1) = 2