Last updated 7 months ago
DFS will only store as much memory on the stack as is required for the longest root to leaf path in the tree. In other words, it space usage is O(h)\text{O}(h)O(h) where hhh is the height of the tree.