Algorithms and Data Structures · Middle · Question 52 of 75

What is the space complexity of a recursive DFS on a tree of height h?

Explanation

At any time the stack holds one frame per level of the current path. For a balanced tree h is log n; for a degenerate one it's n.

Further reading

Problem with a question

Algorithms and Data Structures · Middle · question 52

Test yourself

Take the Algorithms and Data Structures · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz