title: Difference between visitor design pattern and depth first search?
body: <p>A depth first search seem able to perform similar functions as the visitor design pattern.  A visitor allows you to define some data structures and add operations on those structures (in the form of multiple visitors) as needed without modifying the structures themselves.  A description of the visitor pattern is provided on <a href="http://en.wikipedia.org/wiki/Visitor_pattern" rel="nofollow">wikipedia</a>. If we do a depth first search (or any other graph search algorithm like breadth first search) on the data structure, and every time an element of the structure is found, we run our desired operation, then this seems to perform the same function as the visitor.  For example, consider a tree.  Even if some nodes of the tree have different type, we can still check for the node types when doing DFS and then perform different operations based on the node type.</p>