Questions tagged [minimum-spanning-tree]

A minimum spanning tree (MST) or minimum weight spanning tree is a spanning tree of a connected, undirected graph with the least possible weight.

A connected, undirected graph can have many different s. We can assign a weight to each edge, which is a number representing how unfavorable it is, and use this to assign a weight to a spanning tree by computing the sum of the weights of the edges in that spanning tree. A minimum spanning tree (MST) or minimum weight spanning tree is then a spanning tree with weight less than or equal to the weight of any other spanning tree. More generally, any undirected graph (not necessarily connected) has a minimum spanning forest, which is a union of minimum spanning trees for its connected components.

One example would be a cable TV company laying cable to a new neighborhood. If it is constrained to bury the cable only along certain paths, then there would be a graph representing which points are connected by those paths. Some of those paths might be more expensive, because they are longer, or require the cable to be buried deeper; these paths would be represented by edges with larger weights. A spanning tree for that graph would be a subset of those paths that has no cycles but still connects to every house. There might be several spanning trees possible. A minimum spanning tree would be one with the lowest total cost.

(Source: Wikipedia)

560 questions
210
votes
10 answers

When should I use Kruskal as opposed to Prim (and vice versa)?

I was wondering when one should use Prim's algorithm and when Kruskal's to find the minimum spanning tree? They both have easy logics, same worst cases, and only difference is implementation which might involve a bit different data structures. So…
105
votes
15 answers

Difference between Prim's and Dijkstra's algorithms?

What is the exact difference between Dijkstra's and Prim's algorithms? I know Prim's will give a MST but the tree generated by Dijkstra will also be a MST. Then what is the exact difference?
63
votes
8 answers

How to find maximum spanning tree?

Does the opposite of Kruskal's algorithm for minimum spanning tree work for it? I mean, choosing the max weight (edge) every step? Any other idea to find maximum spanning tree?
user467871
52
votes
3 answers

Is Minimum Spanning Tree afraid of negative weights?

This is a follow-up question of Why most graph algorithms do not adapt so easily to negative numbers?. I think Shortest Path (SP) has problem with negative weights, because it adds up all weights along the paths and tries to find the minimum…
Jackson Tale
  • 23,820
  • 29
  • 135
  • 251
35
votes
2 answers

How is a minimum bottleneck spanning tree different from a minimum spanning tree?

A minimum bottleneck spanning tree of a weighted graph G is a spanning tree of G such that minimizes the maximum weight of any edge in the spanning tree. A MBST is not necessarily a MST (minimum spanning tree). Please give an example where these…
Nikunj Banka
  • 10,091
  • 15
  • 68
  • 105
24
votes
3 answers

Minimum Spanning Tree: What exactly is the Cut Property?

I've been spending a lot of time reading online presentations and textbooks about the cut property of a minimum spanning tree. I don't really get what it's suppose to illustrate or even why it's practical. Supposedly it helps determine what edges to…
Delup
  • 255
  • 1
  • 2
  • 6
23
votes
3 answers

All minimum spanning trees implementation

I've been looking for an implementation (I'm using networkx library.) that will find all the minimum spanning trees (MST) of an undirected weighted graph. I can only find implementations for Kruskal's Algorithm and Prim's Algorithm both of which…
22
votes
1 answer

Finding a minimum spanning tree on a directed graph

What algorithm can I use to find a minimum spanning tree on a directed graph? I tried using a modification of Prim's algorithm, but wasn't able to make it work.
user3347255
  • 221
  • 1
  • 2
  • 3
21
votes
2 answers

Update minimum spanning tree with modification of edge

A graph (positive weight edges) with a MST If some edge, e is modified to a new value, what is the best way to update the MST without completely remaking it. I think this can be done in linear time. Also, it seems that I would need a different…
Peeber Burns
  • 211
  • 1
  • 2
  • 3
21
votes
4 answers

Check if edge is included in SOME MST in linear time (non-distinct values)

I am working on an algorithm to check if a given edge is included in one of all possible mst's. For this question, we are considering non-distinct values and our edge e connects vertices A & B. So far, I have: If a path can be made from A to B…
quannabe
  • 307
  • 1
  • 2
  • 9
20
votes
3 answers

Updating a Minimum spanning tree when a new edge is inserted

I've been presented the following problem in University: Let G = (V, E) be an (undirected) graph with costs ce >= 0 on the edges e ∈ E. Assume you are given a minimum-cost spanning tree T in G. Now assume that a new edge is added to G, connecting…
Lynette
  • 201
  • 1
  • 2
  • 3
18
votes
5 answers

Use Dijkstra's to find a Minimum Spanning Tree?

Dijkstra's is typically used to find the shortest distance between two nodes in a graph. Can it be used to find a minimum spanning tree? If so, how? Edit: This isn't homework, but I am trying to understand a question on an old practice exam.
17
votes
4 answers

Differences between Minimum Spanning Tree and Shortest Path Tree

Here is an exercise: Either prove the following or give a counterexample: (a) Is the path between a pair of vertices in a minimum spanning tree of an undirected graph necessarily the shortest (minimum weight) path? (b) Suppose that the minimum…
15
votes
2 answers

An algorithm to see if there are exactly two MSTs in a graph?

I have an undirected connected graph G. I wish to find an algorithm that return true if there are at least 2 MSTs. What if I want to see if there are exactly 2 MSTs?
tom
  • 179
  • 2
  • 6
13
votes
7 answers

Implementing a randomly generated maze using Prim's Algorithm

I am trying to implement a randomly generated maze using Prim's algorithm. I want my maze to look like this: however the mazes that I am generating from my program look like this: I'm currently stuck on correctly implementing the steps highlighted…
donth77
  • 525
  • 1
  • 12
  • 22
1
2 3
37 38