Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

SPANNING TREES

Herwin Manalo
Mark Emman Digdigan
Alfred Barbosa

TREES IN DISCRETE MATH


Mathematicians often use what is referred to as the tree method to represent discrete values. A
definition of a tree in discrete mathematics is that it is a graph or a structure with nodes, or
circles, that are connected by lines. A tree in discrete math is generally defined as acyclic, or the
fact that there is only one path between any of the nodes.

For example, maybe a group of people are taking a trip and begin at node 5. They may choose
option 6 during the trip, which leads them to options 8, 7, and 9 (i.e., specific destinations). Or,
they could choose option 2, which leads them to a separate set of possible destinations. Also,
notice that there is only one path between each option in the tree. In other words, there is only
one way to reach destination 7 (by first choosing destination 8). If someone chooses a route that
does not include node 8, it is not possible to arrive at destination 7. This is what it means to be
acyclic.
An example of a basic number tree

The numbers in each node can be used to represent discrete categories, such as events that can
occur or the outcomes of various decisions that someone can make.

UNDIRECTED GRAPHS
An undirected graph is a graph in which the edges do not point in any direction (ie. the edges are
bidirectional).

CONNECTED GRAPHS
A connected graph is a graph in which there is always a path from a vertex to any other vertex.
A spanning tree is a sub-graph of an undirected connected graph, which includes all the vertices
of the graph with a minimum possible number of edges. If a vertex is missed, then it is not a
spanning tree.
The edges may or may not have weights assigned to them.
The total number of spanning trees with n vertices that can be created from a complete graph is
equal to n(n-2).
If we have n = 4, the maximum number of possible spanning trees is equal to 44-2 = 16. Thus, 16
spanning trees can be formed from a complete graph with 4 vertices.

Normal graph Spanning Tree Spanning Tree Spanning Tree


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

Minimum spanning tree - 1

Minimum spanning tree - 2

WEIGHTED
GRAPH

Minimum spanning tree - 3

The sum of the 4th minimum


Spanning tree is the lowest, Spanning Trees:
thus it is the Minimum Minimum spanning tree - 4
Spanning Tree of the
weighted graph.
Depth-First Search
Depth-First Search/Backtracking
Instead of removing simple circuits (which can be tiresome and time-consuming for larger
graphs) we can create a spanning tree by successively adding edges in an algorithmic fashion.
Depth-first implies we search vertically before horizontally.
1. Choose a “root” vertex for a rooted graph
2. Create an edge by connecting the current vertex to an incident vertex.
3. From the new vertex, repeat step 2 until you can no longer connect any vertices.
4. If all vertices have been visited, you have a spanning tree. If not, go to the next-to-last
visited vertex to form a new path from the vertex.
5. Continue visiting the next-to-last vertex of the current vertex until all vertices have been
visited.

Using a Stack
An easier way to perform the search:
Depth-First Practice
Breadth-First Search
Breadth-first implies we search horizontally before vertically.
1. Choose a “root” vertex for a rooted graph
2. Add all edges incident to that vertex. The newly-connected vertices are level 1 in the
spanning tree.
3. From each vertex in level 1, in order, add all edges incident to the vertices that are not
already included in the spanning tree.
4. Repeat adding levels and edges until all vertices have been visited.

Breadth-First Practice
The minimum spanning tree from a graph is found using the following algorithms:
Prim's Algorithm
Prim's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds the
subset of the edges of that graph which form a tree that includes every vertex and has the
minimum sum of weights among all the trees that can be formed from the graph

Kruskal's Algorithm

Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph as input and finds
the subset of the edges of that graph which form a tree that includes every vertex and has the
minimum sum of weights among all the trees that can be formed from the graph
Prim's Algorithm
It falls under a class of algorithms called greedy algorithms that find the local optimum in the
hopes of finding a global optimum.
We start from one vertex and keep adding edges with the lowest weight until we reach our goal.
The steps for implementing Prim's algorithm are as follows:
 Initialize the minimum spanning tree with a vertex chosen at random.
 Find all the edges that connect the tree to new vertices, find the minimum and add it to
the tree
 Keep repeating step 2 until we get a minimum spanning tree

EXAMPLES:
Kruskal’s Algorithm

It falls under a class of algorithms called greedy algorithms that find the local optimum in the
hopes of finding a global optimum.
We start from the edges with the lowest weight and keep adding edges until we reach our goal.
The steps for implementing Kruskal's algorithm are as follows:
 Sort all the edges from low weight to high
 Take the edge with the lowest weight and add it to the spanning tree. If adding the edge
created a cycle, then reject this edge.
 Keep adding edges until we reach all vertices.

EXAMPLES

You might also like