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)

603 questions
-1
votes
2 answers

Create N-Clusters out of Min spanning tree?

Let say I created a Minimum Spanning Tree out of Graph with M nodes. Is there an algorithm to create N number of clusters. I'm looking to cut some of the links such as that I end up with N clusters and label them i.e. given a node X I can query in…
-1
votes
1 answer

MST challenge gives "time exceeded" error

I am doing the BLINNET problem on Sphere Online Judge where I need to find the cost of a minimum spanning tree. I should follow a structure with Edge and Vertex instances. Vertices represent cities in this case. I get a "time exceeded" error, and I…
-1
votes
1 answer

Confused about Dijkstras shortest path and MST

Is Dijkstra's shortest path algorithm supposed to return a tree like it does in my textbook intro to algorithms? In examples I see online, it just shows the shortest path between 2 vertices. In my textbook it returns a tree with edges connected to…
Chris
  • 437
  • 1
  • 4
  • 18
-1
votes
1 answer

Prim's algorithm modification

G=(V,E), and A⊆E I've been wondering about how to get the minimum spanning tree, if it needs to contain all edges in A (and still must be of minimum weight), by modifying Prim's algorithm. Could someone maybe give me some hints/ideas about how to…
-1
votes
1 answer

Minimum Spanning Tree issue

I found this code online but some parts were missing. I have added statsmodels.api import requests # for making http requests to binance import json # for parsing what binance sends back to us import pandas as pd # for storing…
-1
votes
1 answer

Kruskal algorithm initializing empty set

One of the requirement of Kruskal algorithm is to first initialize an empty set for the vertices but I'm having issues with it. If i were to have a graph represented by [1,2,4] [10,3,5] [6,1,3] where the first index value is the source vertex, and…
Maxxx
  • 3,688
  • 6
  • 28
  • 55
-1
votes
1 answer

What is the best way to search for an edge in the forest using Boruvka MST Algorithm?

I am currently working on coding the Baruvka's algorithm as below. But I am given a question to check for edge e=uv if it already exists in the list of edges which are already taken using greedy choice. How can I search for an edge e with in O(logn)…
Teja
  • 13,214
  • 36
  • 93
  • 155
-1
votes
1 answer

Minimum Spanning tree of a Complete Graph

Assume G = (V,E) is a complete graph. Let the vertices be a set of points in the plane and let the edges be line segments between the points. Let the weight of each edge [a, b] be the length of the segment 'ab'. After reading about Prim's Algorithm…
arsalunic612
  • 129
  • 2
  • 10
-1
votes
1 answer

Finding corresponding graph from given shortest paths

Given n by n points and the distance d between these points, I need to find the corresponding undirected weighted graph that would result in these distances. I tried using Prim's algorithm to find the MST, however this set is of size n-1 and does…
-1
votes
1 answer

Can someone explain how std::greater is used to implement priority_queue

std::priority_queue, std::greater > pq; I cannot understand the work of std::greater in the priority queue. I am replacing minheap by the priority queue. this code is taken from geeksForGeeks implementation of Prims algorithm…
Akash Chandra
  • 375
  • 1
  • 4
  • 13
-1
votes
1 answer

How to find a minimum weight spanning tree for the following graph using prims algorithm

Prim’s Algorithm An algorithm for finding a minimum spanning tree. Begin by choosing any edge with smallest weight, putting it into the spanning tree. Successively add to the tree edges of minimum weight that are incident to a vertex already in…
la3anato
  • 1
  • 3
-1
votes
1 answer

Prevent Cycles in Maximum Spanning Tree

I am trying to create a maximum spanning tree in C++ but am having trouble preventing cycles. The code I have works alright for some cases, but for the majority of cases there is a cycle. I am using an adjacency matrix to find the edges. double…
Tanner
  • 477
  • 7
  • 21
-1
votes
3 answers

Why heap is printing in incorrect order?

I am not sure why my heap method is not printing the heap in the correct order. Can someone tell me what am I doing wrong here? Here is my getHeap method: public static String getHeap(ArrayBasedList edgeList) { // Build the…
learningturtle
  • 128
  • 2
  • 2
  • 11
-1
votes
1 answer

could someone help clarify this implementation of a Minimum Spanning Tree?

I am currently working on a project for data structures due in a couple days and I do not understand the instructions. We are to make a minimum spanning tree via kruskal's algorithm but also need to implement it using an ArrayBasedList, a heap, up…
-1
votes
1 answer

Calculating the set of computers infected by malware, in a network of communicating computers?

A little backstory: It has been a really long time since I've coded in C (a year. Jumping back into this is really overwhelming. I need some advice on implementation. Could someone could explain how you would go about designing this? I understand…