How to get List of Paths found during DFS

Topics: algorithm
Jun 10, 2009 at 4:57 PM

I want to get the list of paths that have been walked during Compute in the following snippet.


var algo = new DepthFirstSearchAlgorithm<FunctionNode, Edge<FunctionNode>>(_graph);

algo.Compute(startNode); //F1

Desired Sample Output: F1->F2->F3; F1->F5

 What is a good way of getting that?


Jun 11, 2009 at 12:14 AM

DFS builds a tree rather than a list of path. You can build the list of path from the tree. 

The DepthFirstSearchAlgorithm does not record anything on its own. You need to attach an observer to it. Read the documentation at the bottom of . There is also probably a helper method to extracts path in the AlgorithmExtensions type.

Jun 11, 2009 at 3:20 AM

Got it, using TryGetPath, Thanks