Add algorithm that builds a spanning forest

Builds a spanning tree for each connected components of the graph.