Minimum Spanning Tree

Prerequisites

Required for a valid graph

  • An undirected graph of nodes
  • Weighted node edges
  • Singular graph of nodes: Kruskal's or Prim's
  • Multiple graphs of nodes: Kruskal's

Algorithms

Prim's Algorithm

Pathfinds, from a random starting node, through the rest of the tree. A priority queue follows the cheapest connections to each node. If a node is the next cheapest path, and is not already part of the graph, it is added. All of the new node's edges are added to the priority queue.

Kruskal's Algorithm

Requires a queue of all edges in the graph. Each edge is connected, cheapest to most expensive. Once all nodes are connected the MST is complete.

Visualization

Click images for their source