City LifeCity LifeDFS With Explicit Stack- September 20, 2007 Recursive depth first search (DFS) is so trivial to write, it is easy to forget that in Java heap size is usually much greater than stack size, so it is always possible to have a graph that is too deep to traverse recursively. Easy, at least, until StackOverflowException knocks your application into the middle of next week.No problem, you say. I'll just rewrite the DFS using an explicit stack. Let's see, the algorithm I learned in school is something like:public void dfs(Vertex root) Stack s..http://www.jroller.com/bobfoster/entry/depth_first_search_with_explicit |