image thumbnail

Minimum Spanning Tree

version 1.0.0 (1.67 KB) by Ashim Gautam
Implementation of Prim algorithm to solve Minimum Spanning Tree (MST)

224 Downloads

Updated 03 Mar 2019

View License

The input Matrix is edge-weighted matirx with not connected edge assigned as 0
>>A =
[0 192 344 0 0 0 0 0 0 0 0;
192 0 309 0 555 0 0 0 0 0 0;
344 309 0 499 0 0 0 0 0 0 0;
0 0 499 0 840 0 229 286 0 0 0;
0 555 0 840 0 237 0 0 0 0 0;
0 0 0 0 237 0 729 0 0 793 0;
0 0 0 229 0 729 0 383 0 0 0;
0 0 0 286 0 0 383 0 929 0 0;
0 0 0 0 0 0 0 929 0 934 581;
0 0 0 0 0 793 0 0 934 0 633;
0 0 0 0 0 0 0 0 581 633 0;]
>>route=prims(A,1)
1 2 192
2 3 309
3 4 499
4 7 229
4 8 286
2 5 555
5 6 237
6 10 793
10 11 633
11 9 581

Cite As

Ashim Gautam (2021). Minimum Spanning Tree (https://www.mathworks.com/matlabcentral/fileexchange/70454-minimum-spanning-tree), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2018b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!