Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spanning Tree VS. Spanning Forest

What's the difference between a Spanning Tree and a Spanning Forest in graphs, conceptually.

Also, is it possible to construct a Spanning Forest through DFS or BFS traversals? Why? How?

I understand the Spanning Tree, but I couldn't find any clear explanations about spanning forests. Even Wikipedia (https://en.wikipedia.org/wiki/Spanning_tree), doesn't give a clear definition about it. My book (Data Structures & Algorithms, Wiley - sixth edition) also has no definition for spanning forests.

I was wondering, if we have a graph with for example three connected components in it, is it possible to construct a spanning forest by DFS/BFS traversals?

like image 449
Nima Salami Avatar asked Apr 06 '17 10:04

Nima Salami


People also ask

What is spanning tree and spanning forest?

For other authors, a spanning forest is a forest that spans all of the vertices, meaning only that each vertex of the graph is a vertex in the forest. For this definition, even a connected graph may have a disconnected spanning forest, such as the forest in which each vertex forms a single-vertex tree.

What is difference between tree graph and forest?

A tree is a connected graph with no cycles. A forest is a graph with each connected component a tree. A leaf in a tree is any vertex of degree 1. Example Figure 11 shows a tree and a forest of 2 trees.

What is the difference between a spanning tree and a minimal spanning tree?

A minimum spanning tree is a spanning tree in which the sum of the weight of the edges is as minimum as possible.

How many types of spanning trees are there?

If a graph is a complete graph with n vertices, then total number of spanning trees is n(n-2) where n is the number of nodes in the graph.


1 Answers

When there is only one connected component in your graph, the spanning tree = spanning forest.

But when there are multiple connected components in your graph. For example in following picture we have 3 connected components.:

enter image description here

So for each component, we will have a spanning tree, and all 3 spanning trees will constitute spanning forest

I was wondering, if we have a graph with for example three connected components in it, is it possible to construct a spanning forest by DFS/BFS traversals?

Yes it is possible. When there is only 1 connected component, your BFS or DFS will terminate visiting all the vertices and you will have a spanning tree (which in this case is equal to spanning forest).

But when you have more than 1 connected component, like in the picture, the only thing you have to do is start another BFS or DFS from an unvisited vertex. Your algorithm terminates when there is no unvisited vertex left and each BFS or DFS traversal will yield a spanning tree.

like image 192
Sumeet Avatar answered Nov 16 '22 02:11

Sumeet