Reputation: 89
I have a question about implementing Boruvka's algorithm for Minimum-Spanning-Trees.
Assume we have the following graph:
It is fairly simple and clear to me how to find the smallest connection/edge of each node/vertex. My question is about how you perform the next step.
To my understanding, in Boruvkas algorithm you perform the action of going over all components and combining a component with another through its own lightest connection. In the above picture, this would mean combining the components {0} and {1} into one (lets call it component {0,1}) aswell as combining the components {2} and {3} into component {2,3}. So our list of components goes from {{0},{1},{2},{3}} to {{0,1},{2,3}}. While performing this operation, we also save the edges that connect those components into one in a separate list. At the end of this first step, the list of edges that form a Minimum Spanning Tree would look like this: {2,2}
My question: How exactly can I turn {0} and {1} into a single component and perform the next step? Assume I have a larger graph and the following components after performing the first step: {{0,1,2,3,4,5},{6,7,8,9,10}}. What exactly do I do at this stage? Do I have to look through all the edges of 0 - 5 that connect it to any vertex from 6 - 10 and choose the lightest one?
Upvotes: 1
Views: 117
Reputation: 349956
How exactly can I turn {0} and {1} into a single component
First you add the connecting edge to the solution set of edges. The challenge is to know (during the algorithm) for any pair of nodes whether they belong to the same component. There are several ways to do this. One is to use a disjoint set, also known as union-find.
...and perform the next step? Assume I have a larger graph and the following components after performing the first step: {{0,1,2,3,4,5},{6,7,8,9,10}}. What exactly do I do at this stage? Do I have to look through all the edges of 0 - 5 that connect it to any vertex from 6 - 10 and choose the lightest one?
You'll have to look through all the edges that have one of the nodes in the first component (0 - 5): consider only those edges that connect to a node that is not in the same component, and take the lightest one.
Upvotes: 2