Chapter 7 · SimulationMinimum Spanning Tree? ← Chapter 7 Nodes Generate Prim's Algorithm Kruskal's Algorithm Cancel SlowNormalFast MST edgeexaminedcrosses cutReady. CloseMinimum Spanning TreeA connected, weighted graph is generated; Prim's and Kruskal's algorithms are compared step by step.How to useEnter the number of nodes (2–15) and press Generate. The nodes are placed on a circle and consecutive nodes are joined into a path (so the graph is always connected), then random extra chords are added; weights range from 1 to 20.Drag nodes to rearrange the drawing (not while an algorithm is running).Run Prim's Algorithm (starts at node 0) or Kruskal's Algorithm. Cancel stops the animation; the speed selector changes the pace.Thick edges belong to the tree. Prim's shows the edges crossing the cut between the tree and the remaining nodes; Kruskal's shows each edge it examines and marks edges skipped because they would close a cycle.Prim's algorithmStarts at one node and repeatedly picks the cheapest edge that connects the current tree to a new node. With a binary heap it runs in O(E log V) time.Kruskal's algorithmProcesses edges from the smallest weight to the largest and adds an edge only if it does not form a cycle. The cycle check uses a union-find structure (path compression and union by rank); sorting dominates the running time: O(E log E).Both algorithms are correct because of the cut property: the lightest edge crossing any cut belongs to some minimum spanning tree. If several edges have equal weight the two algorithms may pick different trees, but the total weight is always the same.