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 nn vertices that can be created from a complete graph is given by the formula:

    • n(n−2)n^{(n-2)}

    • Example: For n=4n=4, the maximum number of possible spanning trees is:

    • 4(4−2)=164^{(4-2)} = 16

  • 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 ∣V∣−1|V| - 1 edges, where ∣V∣|V| 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:

    1. Start with a randomly chosen vertex.

    2. Find edges connecting the tree to new vertices and add the edge with the lowest weight.

    3. Repeat until all vertices are included in the minimum spanning tree.

  • Complexity: The time complexity of Prim's algorithm is O(EextlogV)O(E ext{ log } V).

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:

    1. Sort all edges from lowest to highest weight.

    2. Add the edge with the lowest weight to the spanning tree if it does not create a cycle.

    3. Repeat until all vertices are included.

  • Complexity: The time complexity of Kruskal's algorithm is O(EextlogE)O(E ext{ log } E).


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: O(V2)O(V^2), improved to O(EextlogV)O(E ext{ log } V) with Fibonacci heaps.

    • Kruskal's: O(EextlogV)O(E ext{ log } V).

  • 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.