Tags: depth first search, lecture-13, trees
What is the time complexity of depth first search (DFS) when run on a tree with \(n\) nodes?
\(\Theta(n)\).
DFS takes \(\Theta(V + E)\) time, and a tree with \(n\) nodes has \(n - 1\) edges, so it takes \(\Theta(n + (n - 1)) = \Theta(n)\) time.
No 🌶️ problems in this topic.