Sorting vertices by Minimum Spanning Trees in a forest of MSTs

148 Views Asked by At

Consider a number of vertices. They are separated into a number of Minimum Spanning Trees (MSTs) (so there's a forest of MSTs) using Kruskal's algorithm. For each vertex I need to know in which MST they are located. Each MST will be assigned a unique ID.

When completed I will know, for example, that Vertex #12 is in MST #2.

This is my best attempt at this. As you can see the algorithm failed because it falsely tagged one MST as two separate MSTs (Blue Group 0 and Blue Group 1):

enter image description here

I'm looking for an algorithm that can do this. Thanks in advance. I'm a programmer not a mathematician.

To answer questions from comments:

  1. MST = Minimum Spanning Tree
  2. I don't know in advance how many MSTs I'll end up with.
  3. Basically, I'm confronted with the forest of MSTs and then I have to count them and tag the vertices.
1

There are 1 best solutions below

1
On

You can try nearest-neighbor clustering and adjust the criterion distance $d$: Nearest-neighbor clustering:

enter image description here