Lab Documentation

Minimum Spanning Tree System Guide

Exit

Categories

getting started

Introduction to Minimum Spanning Trees

Understand the core mathematical definition of Spanning Trees and why we compute them.

A Spanning Tree of a connected, undirected graph is a subgraph that is a tree (contains no cycles) and connects (spans) all the vertices together.

The Minimum Spanning Tree (MST)

For a weighted graph, the MST is the spanning tree with the minimum possible total edge weight. If there are $V$ vertices, an MST will always contain exactly $V - 1$ edges.

MST algorithms find immediate, daily application in real-world infrastructure systems such as designing high-efficiency computer systems, power grids, telecommunication hubs, pipeline networks, and finding optimal travel matrices.

sandbox

Drawing Nodes & Structuring Graphs

Learn the mouse & touch gestures to populate customized node points in the interactive workspace.

The visualization canvas is a fully interactive, state-governed sandbox supporting precise graph creation. Learn the visual interactions:

Add Nodes

Select Add Node mode, then click anywhere on the grey background to draw a node anchor point.

Drag & Move Nodes

Use Select/Move mode. Click, hold, and drag any node to reposition it dynamically. Edges automatically stretch.

Tip on Layouts: At any time, use the Auto Layout action on the bottom toolbar to automatically organize node clusters neatly using a physics-directed force layout scheme.

sandbox

Connecting Edges & Setting Weights

Establish bidirectional links between nodes and assign numerical cost weights.

Weights define the cost overhead of traversing routes in your graph. Connections are bidirectional:

1
Initiate Edge Draw: Swap the toolbar to Add Edge mode.
2
Link the Nodes: Click on the starting node, drag your mouse (or drag the touch vector), and release the cursor on top of the target node.
3
Adjust Weight Costs: In Select Mode, double-click or double-tap on any weight label box. A small slider or inline overlay input will appear, letting you specify custom values from 1 to 99 instantly.
sandbox

Deleting Elements & Restoring Sandbox

Safely prune edges and nodes, or wipe clean the workspace to start fresh on a new topology.

Avoid clutter and rebuild structures easily with complete pruning tools:

  • Using Delete Mode: Swap to Delete mode on the bottom menu, then click on any node or edge to erase it from the graph state immediately.
  • Node Cascading: When you delete a node, any connecting edges associated with it are automatically removed to prevent floating invalid pathways.
  • Clear Graph: Use the Clear Canvas button in the left controller to instantly wipe all nodes and edges to begin fresh.
sandbox

Double-Tap Shortcut: Create Nodes Instantly

Draw node anchors instantly anywhere in the workspace without changing tools.

When constructing complex graphs, constantly toggling toolbar buttons can slow you down. The canvas includes high-fidelity double-tap or double-click shortcuts:

2x
Double-Tap and Spawn Node

Simply double-tap or double-click on any empty space around the workspace background. A new node is instantly drawn at your cursor or tap coordinates, even if you are currently in another mode like Select/Move!

sandbox

Double-Tap Shortcut: Connect Edges Quickly

Start an edge connection immediately by double tapping any existing node.

Connecting isolated elements can be triggered directly using the double-tap shortcut:

⚡ Steps for Double-Tap Edge Creation
  1. Double-tap (or double-click) on any existing node on the canvas.
  2. An interactive Add Edge Dialog will slide open automatically.
  3. Select your target node from the searchable dropdown list, type in the desired weight cost, and click Create Edge to link the pair instantly.
sandbox

How to Edit Edge Weights

Modify edge weight costs at any time using inline interactive controls.

Changing weights allows you to experiment with how algorithms prioritize routes. To edit any edge weight:

Method: Double-Click the Weight Label

When in Select/Move or Add Edge mode, double-click or double-tap on the numeric weight label box floating along any edge segment. This focuses a responsive input fields container:

  • Use the slider to scrub values smoothly from 1 to 99.
  • Or click the input field, type in your final cost value, and press Enter (or tap Save).
  • The new weight will be integrated immediately, refreshing any active algorithm visual paths!
algorithms

Kruskal's Algorithm Framework

A greedy, edge-driven search that sorts connections and maps disjoint partitions.

Kruskal's Algorithm is a classic greedy algorithm that discovers the MST by processing edges in non-decreasing order of their weights.

# Kruskal Pseudocode Overview
1. Sort all edges by ascending weight.
2. Initialize a disjoint-set (Disjoint Set Union - DSU) structure.
3. For each sorted edge (u, v):
a. If u and v belong to different subsets:
i. Union the subsets of u and v.
ii. Add the edge (u, v) to the MST.
b. Otherwise, discard the edge (creates a cycle).
4. Stop when the MST holds exactly V - 1 edges.
Union-Find Engine & Cycle Prevention

Kruskal utilizes a fast **Disjoint Set (Union-Find)** structure to confirm if adding an edge connects two previously isolated networks. It implements path compression and union-by-rank, offering almost constant-time cycle assessments of $O(\alpha(V))$.

algorithms

Prim's Algorithm Framework

A greedy, node-growing algorithm that expands outwards from a starting seed point.

Prim's Algorithm constructs the MST incrementally by starting from a chosen vertex (seed) and growing the tree outward.

# Prim Pseudocode Overview
1. Choose an arbitrary starting node. Mark it as visited.
2. Insert all edges connecting the starting node into a Min-Heap.
3. While the heap is not empty and nodes remain unspanned:
a. Extract the minimum weight edge (u, v) from the heap.
b. If the target node v is already visited, discard.
c. Otherwise:
i. Mark v as visited and add edge (u, v) to MST.
ii. Push all edges starting from v to unvisited nodes into the heap.
Heap Operations

At each step, Prim looks at all candidate edges connecting our growing set of spanned nodes to other unvisited nodes throughout the graph, selecting the absolute cheapest connection via an efficient Priority Queue.

algorithms

Side-by-Side Comparison Matrix

An objective analytical comparison of both major algorithms on different graph types.

Depending on graph density (the relationship between the number of Vertices $V$ and Edges $E$), one algorithm typically outperforms the other:

PropertyKruskal's AlgorithmPrim's Algorithm
Search ParadigmEdge-centric traversalNode-centric expanding traversal
Time Complexity$O(E \log E)$ or $O(E \log V)$$O(E \log V)$ using Min-Heap
Space Complexity$O(V + E)$ for sorting and DSU$O(V + E)$ for Priority Queue
Recommended forSparse graphs (fewer edges)Dense graphs (heavily connected)
Cycle CheckingExplicitly checked via DSUImplicitly avoided via Visited Set
playback

Tuning Simulation & Speed Controls

Familiarize yourself with the playback dashboard to step forward and backward.

The playback dashboard operates like an interactive media player, allowing you to scrutinize every decision made by the underlying mathematical models:

Play / Pause
Auto-steps forward at the user-defined interval.
⟨ ⟩Previous / Next Step
Manually step to investigate specific logical choices.
Speed Multiplier Slider
Fine-tune simulation interval between 0.25x and 4.0x speed.
playback

Deciphering the Spanning Complete Modal & Metrics

Analyze final execution metrics, cumulative costs, connection records, and review pathways when an algorithm resolves.

When an algorithm completes its work by fully spanning the graph or exhausting reachable vertices, the interactive Spanning Complete Modal will lock in your final stats. Here is a breakdown of what every field on this modal signifies:

⭐ Calculated Metrics
  • Total Spanned Cost: The mathematical sum of all selected edge weights in the Minimum Spanning Tree. This represents the absolute cheapest cost to keep the graph points reachable and fully connected.
  • Nodes Connected: The total number of vertices ($V$) spanning the active topology. A complete MST always encompasses all connected nodes of the main graph component.
  • Edges Included: The number of edges inside your MST. By tree definition, a connected graph with $V$ vertices will always have exactly $V - 1$ optimal edges in its MST.
  • Edge Evaluations: The total count of inspections, comparisons, or queue checks executed before finalizing. This highlights the algorithm's footprint and how many cycles were spent verifying connectivity.
🎮 Navigation & Action Options

Take control of the visualization flow after completion using two specialized options:

  • Reset Environment: Click this button to wipe the spanning solution state and restore the graph back to active Sandbox editing mode. You can instantly change weights, draw new edges, or reposition vertices.
  • Analyze Saved Path: Dismisses the modal dialog while preserving the completed tree on the canvas. This allows you to explore the final visual graph, review state steps manually using timeline controls, or hover over optimal paths.
  • Reopen Completion Modal: If you closed the modal to inspect the graph and want to see the performance stats again, look for the green 🏆 Reopen Completion Modal button in the sidebar panel or canvas tools.
visuals

Visual Representation Legend

Understand the geometric colors and animations representing graph states during runs.

Keep track of the algorithm's status by monitoring changes in the canvas layout elements:

Node States
Standard Sandbox NodeSlate Outer
Currently InspectedIndigo Pulse
Spanned node (Completed)Green Glow
Edge States
Currently InspectedThick Indigo Line
Accepted (Optimal path)Pure Green edge-accepted
Rejected (Avoids cyclic loops)Faded Dotted Rose

Ready to experiment, scholar?

Unlock deep structural algorithm steps. Try drafting custom networks, dragging connections or altering edge weights in our visual laboratory dashboard.