Developing the answer of Aasmund Eldhuset: if the weights in MST are limited by numbers in the range 0, 1, 2, 3, ..., U-1, then you can adapt many of the existing algorithms to run in (near) linear time, if U is a constant .
For example, take the Kruskal algorithm. The first step in the Kruskal algorithm is sorting the edges in order of increasing weight. You can do this in time O (m + U) if you use count sorting or time O (m lg U) if you use radix sort. If U is a constant, then both of these sorting procedures take linear time. Therefore, the execution time of the Kruskal algorithm in this case will be O (m? (M)), where? (m) is the inverse function of Ackerman, since the limiting factor will be the time it takes to save the disjoint states to establish the forest.
As an alternative, consider the Prim algorithm. You need to maintain a priority queue of distances between candidates to nodes. If you know that all edges are in the range [0, U), then you can do it in a naively naive way by simply saving the array from the U bucket, one at a time to one of the possible priorities. When inserting into the priority queue, it just requires that you drop the item into the right bucket. You can make a decrease button by displacing an item and moving it to the bottom bucket. Then you can search for mines by scanning the buckets. This causes the execution time of the algorithm to be O (m + nU), which is linear if U is a constant.
source share