title: How to do a Tree Search?
body: <p>I have a TreeView that I want to search. Any items that contain the search term should remain visible as well as their ancestors (since, obviously, I can't show them if they're orphaned).</p>
  <p>I know one way to do this and it's not a problem, but it just makes me curious if there are solid algorithms for this that have been out there for a long time that I should look into. For example, my approach is going to be to use a recursive routine to go into each subtree of each node and then if a node matches the search term I will need to mark it, as well as all of its ancestors, to be included in the results. Or possibly some other method?</p>
  <p>I'm familiar with at least 4 ways to store hierarchical data in a relational database, and different ones are good for different applications. So likewise I get the feeling that my initial approach here is probably the most intuitive but may not be the one I want.</p>
  <p>For example I'm wondering if I were to, say, assign a path to each node (like with a materialized path or enumerated path hierarchy) then maybe it would be easier and/or faster to traverse the nodes as a flat list in order to get the ones I need.</p>
  <p>Sorry in advance if this is the wrong place to post this. Maybe it should be posted in softwareengineering or another forum since I'm not necessarily looking for an implementation specific to c#, but more just wanting to know if there are well known algorithms out there that I might know had I studied data structures in college? Please feel free to suggest another forum for me to ask this in if it doesn't fit here.</p>