Given a connected and undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices together. A single graph can have many different spanning trees. A minimum product spanning tree for a weighted, connected and undirected graph is a spanning tree with weight product less than or equal to the weight product of every other spanning tree. The weight product of a spanning tree is the product of weights corresponding to each edge of the spanning tree. All weights of the given graph will be positive for simplicity.
This problem can be solved using standard minimum spanning tree algorithms like krushkal and prim’s algorithm, but we need to modify our graph to use these algorithms. Minimum spanning tree algorithms tries to minimize total sum of weights, here we need to minimize total product of weights. We can use property of logarithms to overcome this problem.
As we know,
log(w1* w2 * w3 * …. * wN) = log(w1) + log(w2) + log(w3) ….. + log(wN)
We can replace each weight of graph by its log value, then we apply any minimum spanning tree algorithm which will try to minimize sum of log(wi) which in-turn minimizes weight product.
For example graph, steps are shown in below diagram,
In below code first we have constructed the log graph from given input graph, then that graph is given as input to prim’s MST algorithm, which will minimize the total sum of weights of tree. Since weight of modified graph are logarithms of actual input graph, we actually minimize the product of weights of spanning tree.
Edge Weight 0 - 1 2 1 - 2 3 0 - 3 6 1 - 4 5 Minimum Obtainable product is 180
This article is contributed by Utkarsh Trivedi. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Kruskal's Minimum Spanning Tree using STL in C++
- Find the weight of the minimum spanning tree
- Boruvka's algorithm for Minimum Spanning Tree
- Applications of Minimum Spanning Tree Problem
- Minimum spanning tree cost of given Graphs
- Minimum Bottleneck Spanning Tree(MBST)
- Prim’s Minimum Spanning Tree (MST) | Greedy Algo-5
- Reverse Delete Algorithm for Minimum Spanning Tree
- Minimum Spanning Tree using Priority Queue and Array List
- Find the minimum spanning tree with alternating colored edges
- Kruskal’s Minimum Spanning Tree Algorithm | Greedy Algo-2
- Product of minimum edge weight between all pairs of a Tree
- Types of Spanning Tree Protocol (STP)
- Spanning Tree With Maximum Degree (Using Kruskal's Algorithm)
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
- Problem Solving for Minimum Spanning Trees (Kruskal’s and Prim’s)
- Maximum product of two non-intersecting paths in a tree
- Minimum steps to color the tree with given colors
- Find the root of the sub-tree whose weighted sum XOR with X is minimum
- Find the root of the sub-tree whose weighted sum is minimum