pythonnetworkxgraph-theoryspanning-tree

Definition of a spanning tree


I want to check if my understanding of a spanning tree (for undirected and connected graphs) is correct.

From, what I have read online. A spanning tree is a subset of a graph, it contains the same amount of vertices of the graph, however it has a minimum amount of edges. There can also be many different spanning trees for a graph.

I have seen some illustrations of spanning trees and their graph so i have tried to come up with my own example.

house graph

So this image shows a house shaped graph. If I was to get rid of one edge in that house graph, this would be a spanning tree since there is an alternate pathway to get from one node to another.

I could also potentially get rid of two edges if I make sure that there is still a path that exists between the two nodes.

Am I correct in this assumption?


Solution

  • No, you are not correct in this assumption, because you will have to remove 2 edges in order to build a spanning tree. Removing one edge will not work.
    The house graph of you picture has 5 vertices, and 6 edges.
    A tree with n vertices has n-1 edges, so a tree with 5 vertices needs to have 4 edges.

    A spanning tree is not a tricky object, it really stands by its name. spanning because it covers all vertices, and tree because it is a tree.

    If you were to remove a single edge, there will still be a cycle in your graph, so it cannot be a tree (which is, by definition, a connected acyclic graph).

    That is one thing that is very easy to find out when you want to build a spanning tree of a graph, it is the number of edges to remove (or to keep, which is equivalent). The formula #vertices = #edges + 1 always holds in a tree.
    I advice you to have a look at all the definitions and characterisations of a tree, it is always useful to have more than one in mind, especially when it comes to trees.