Search code examples
c++algorithmboostdepth-first-search

Performing depth-first algorithm from a specific vertex


I am trying to find a way to perform the depth-first algorithm from a specific vertex by using the boost graph library.

The depth-first algorithm provided by Boost library evaluates the graph beginning from the start vertex to the last vertex. But what if the graph has to be searched from a specific vertex?

Any suggestions?


Solution

  • Have a look at BGL's documentation.

    There is an overload where you can provide the start vertex.

    template <class Graph, class DFSVisitor, class ColorMap>
    void depth_first_search(const Graph& g, DFSVisitor vis, ColorMap color, 
                            typename graph_traits<Graph>::vertex_descriptor start)