ChetOS.net

Graph Traversal

If you change a graph traversal algorithm from stack-based to queue-based, you change it from depth-first to breadth-first.

Breadth-first is useful when you want to process siblings before processing their children.  Depth-first traversal processes as deep as it can before backtracking.

Interesting note: although this is clearly a use for recursion, either method can be implemented iteratively to save space on the stack (and sidestep potential stack overflow issues when there are many nodes).
Posted by Chet at 3:17 PM

Comments

No Comments have been Posted.

Post a Comment

Feel Free To Share Your Thoughts
You can use [b], [u], [i], and [url]
Simple CAPTCHA: If green is 9 and blue is 25, what color is red?
Optional
Name
Website
© 2010 Chet Zema π