Spanning Trees and Algorithms
Spanning Trees
Definition of Spanning Tree
Spanning Tree: A sub-graph of an undirected connected graph that includes all the vertices with the minimum possible number of edges.
If one vertex is missed, it is not a spanning tree.
The edges may or may not have weights assigned to them.
Key Concepts Related to Spanning Trees
Undirected Graph: A graph where edges do not have a direction, meaning they are bidirectional.
Connected Graph: A graph where there is always a path from any vertex to any other vertex.
Properties of Spanning Trees
Number of Spanning Trees: The total number of spanning trees with vertices that can be created from a complete graph is given by the formula:
Example: For , the maximum number of possible spanning trees is:
Presence of Edges and Vertices: All possible spanning trees of a graph have the same number of edges and vertices.
Cycles: A spanning tree can never contain a cycle.
Connectivity: A spanning tree is minimally connected; if one edge is removed, it becomes disconnected.
Acyclic Nature: A spanning tree is maximally acyclic; adding one edge to it creates a cycle.
Minimum Spanning Trees: It is possible to have more than one minimum spanning tree if the weights of some edges are the same.
Minimum Edges in Tree: A spanning tree will always have edges, where is the number of vertices.
Examples of Spanning Trees
Consider given graphs which illustrate various spanning trees derived from an original graph where all vertices are connected without cycles.
Illustrations indicate possible spanning trees formed from sample graphs, labeled from A to D.
Minimum Spanning Trees (MST)
Minimum Spanning Tree: A spanning tree where the sum of the weights of the edges is minimized.
Significance: Optimization of total edge weight to connect all vertices.
Example Context: Using weights associated with edges in a connected graph to define a minimum spanning tree by computing their sum.
General Properties of Minimum Spanning Trees
More than one minimum spanning tree can exist based on edge weights.
In directed graphs, the minimum spanning tree minimizes edge weight.
Applications of Spanning Trees
General Applications of Spanning Trees:
Computer Network Routing Protocol
Cluster Analysis
Civil Network Planning
Specific Applications for Minimum Spanning Trees:
Path finding in geographic maps.
Designing networks like telecommunications, water supply, and electrical grids.
Concrete example: Laying cables in a new neighborhood while minimizing costs based on path weight.
Algorithms for Finding Minimum Spanning Trees
Prim’s Algorithm
Description: Prim's algorithm is a minimum spanning tree algorithm that selects edges with the lowest weight to connect all vertices in the graph.
Greedy Algorithm: It follows a greedy approach to find local optima aiming for a global optimum.
Steps to Implement:
Start with a randomly chosen vertex.
Find edges connecting the tree to new vertices and add the edge with the lowest weight.
Repeat until all vertices are included in the minimum spanning tree.
Complexity: The time complexity of Prim's algorithm is .
Kruskal’s Algorithm
Description: A minimum spanning tree algorithm that builds a spanning tree by sorting edges and selecting those that do not form a cycle.
Greedy Nature: Also follows a greedy approach to choose the lowest weight edges.
Steps to Implement:
Sort all edges from lowest to highest weight.
Add the edge with the lowest weight to the spanning tree if it does not create a cycle.
Repeat until all vertices are included.
Complexity: The time complexity of Kruskal's algorithm is .
Comparative Analysis of Prim's and Kruskal's Algorithms
Starting Point:
Prim's starts from any vertex in the graph.
Kruskal's starts from the edge with the minimum weight.
Traversal Behavior:
Prim’s can visit nodes multiple times to minimize distance.
Kruskal’s visits each node only once.
Complexity Statements:
Prim’s: , improved to with Fibonacci heaps.
Kruskal's: .
Graph Connectivity:
Prim’s works on connected graphs.
Kruskal’s can generate forests as it works on disconnected graphs.
Efficiency in Different Graph Types:
Prim’s is more efficient in dense graphs.
Kruskal’s is better in sparse graphs.
Preference of Data Structures:
Prim’s prefers list data structures.
Kruskal’s prefers heap data structures.