Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Filter by
Sorted by
Tagged with
0 votes
1 answer
81 views

Postgres Recursive Query Behavior

I have a table test with two columns, each referencing the other ID1 ID2 2 1 3 2 4 3 5 4 Given an id, I need to traverse the chain to return all the rows traversing the chain. Below is the query I ...
sg2000's user avatar
  • 309
-1 votes
1 answer
108 views

Kruskal's Algorithm Minimum Spanning Tree (Disjoint Set data structure)

I would like to generate a minimum spanning tree for the following graph: I am using the disjoint set data structure and I am having trouble with the union (Union Rank) operation. The edges get ...
EngineerP's user avatar
-2 votes
1 answer
137 views

Constrained MST: Find a spanning tree of weight ≤ T that minimizes the number of red edges

We are given an undirected graph ( G = (V, E) ), where: ( V ) is the set of vertices (or nodes), ( E ) is the set of edges. Each edge ( e ∈ E ) has two attributes: A weight ( w(e) ), which is a ...
Ikshvaku's user avatar
  • 103
1 vote
1 answer
314 views

Efficiently Find Approximate Minimum Spanning Tree of a Large Graph

I have a large number of nodes, ~25000, each with a 3D position. I want to produce a sparsely connected graph, with edges given by the distance between nodes, for use in a GNN. Algorithms to find the ...
DrDino's user avatar
  • 23
4 votes
4 answers
408 views

Fast way of detecting outliers in 2D space

I have hundreds of millions of point clouds like the following: I want to remove outliers 1, 2, 4, 5, 6, 7. The safest bet is to build a minimum spanning tree connecting all the points and remove ...
user2961927's user avatar
  • 1,790
1 vote
1 answer
80 views

How to extract graph edges in a specific order from networkx?

I am trying to find the shortest path that passes through a set of points that are pretty much aligned. This needs to work in all directions, so I can't just sort them by x or y values. The solution I ...
user19109076's user avatar
0 votes
1 answer
69 views

What is the complexity of the following code? Is it O(n^3log(n))?

What is the complexity of the following code? Is it O(n^3log(n))? #G is an undirected dense graph, which has N vertices. import networkx as nx def cal_minimax_path_matrix(G): MST = nx....
Mike Mathcook's user avatar
2 votes
1 answer
217 views

Minimum spanning tree variation for node-weighted graph

I'm trying to solve a variation of the minimum spanning tree problem; I have a graph where there are certain key nodes and optional nodes. Each optional node has a weight and we need to find a subset ...
WARdd's user avatar
  • 116
2 votes
0 answers
234 views

Fastest way to run Steiner tree on large graph?

I have a very large graph (25GB, 35 million edges) and a collection of nodes. I want to find a tree that has all of those nodes; a tree that minimizes the number of edges but maximizes the number of ...
Caroline's user avatar
  • 167
1 vote
2 answers
117 views

MST - Question with cycle in length 6 or less

I came across a question that I tried to solve by myself but I didn't come up with a satisfactory enough answer. The Question: Given an undirected graph G = (V, E) with weight function w: E->R ...
ATB's user avatar
  • 141
0 votes
0 answers
202 views

Manhattan Distance Minimum Spanning Tree

I'm working on a Steiner Tree algorithm for rectilinear graphs (Manhattan distance) and first of all I need to compute a minimum spanning tree as an upper bound, also with Manhattan distance. This is ...
grünewuzz17's user avatar
0 votes
1 answer
144 views

Inconsistent results when using Scipy Minimum Spanning tree with sparse and dense inputs

I have the adjacency matrix of a graph stored as sparse scipy scr matrix. When I call the scipy.sparse.csgraph.minimum_spanning_tree function, my generated sparse array have too few non zero values ( ...
FO1234's user avatar
  • 5
0 votes
1 answer
79 views

Proof in Minimum Spanning Trees(More of a mathematical problem)

As we know minimum spanning tree tries to achieve the "minimum" sum of weights of the tree. Now my questions. Using prim and kruskal algorithms, 1) If we change what we are trying to ...
dimitrisaspas's user avatar
0 votes
3 answers
118 views

Problem removing from Java-HashSet while implementing Kruskal's algorithm

in the following code I am trying to implement Kruskal's algorithm to compute the minimal spanning tree of a graph. The problem is that removing sets from the connected components does not work ...
sorry's user avatar
  • 131
0 votes
1 answer
258 views

How to annotate distances of distance matrix to edges of a minimum-spanning-tree in R?

Aloha guys! I am trying to create a Minimum-Spanning-Tree with ggplot, because I want to make use of the ggplot2 and especially ggnetwork functions like geom_edgelabel() to receive a sophisticated, ...
infinity-a11y's user avatar
0 votes
0 answers
66 views

Prim’s MST Algorithm

I just finished an exercise on the application of Prim's theorem. However, I don't have the solution to this problem, but I found an answer in this exercise. Could someone verify that the solution I ...
Student123's user avatar
0 votes
0 answers
256 views

generate all mst's with igraph in r

Given that for a graph the Minimum Spanning Tree might not be unique I want to generate all distinct MSTs with igraph in R. Is that possible? For now, I'm obtaining a single MST: completeGraph <- ...
Dr. No's user avatar
  • 156
0 votes
0 answers
50 views

Finding minimum spanning tree with Kruskal's, but there are overlap vertex

I tried to find minimum spanning tree with given graph (as adjacency list), priority queue and union-find method (with kruskal). But there are two differences with my desired output : First, The ...
bFur4list's user avatar
  • 133
1 vote
0 answers
56 views

In Kruskal's Algorithm, why does the union procedure check whether r_x == r_y since the opposite was required to call union()?

In Algorithms [DPV] Section 5.1.3, the authors outlined Kruskal's Algorithm. In the algorithm itself, while iterating through all edges on the graph, they compare whether find(u) != find(v). If so, ...
OOProg's user avatar
  • 189
2 votes
2 answers
55 views

Operating on a pair of elements in an array and dropping one

There is a class of questions, that requires us to randomly select two elements from a given array, perform an operation on those elements, add the result to an "answer" and then drop any ...
thenonacmguy's user avatar
-1 votes
1 answer
109 views

minimum time to travel between stations

I have implemented a Java program that aims to find the minimum time required to reach each station based on the given bus schedules using Breadth-First Search (BFS). However, the program consistently ...
TaHaBH7's user avatar
2 votes
2 answers
333 views

Algorithm for finding approximate minimum tree that spans a given subset of vertices?

Given a weighted graph and a subset of two vertices in the graph, finding a minimum tree that spans all (both) vertices in the given subset reduces to finding a shortest path between the two vertices ...
HelloGoodbye's user avatar
  • 3,998
-1 votes
2 answers
343 views

Fastest Algorithm/Software for MST and Searching on Large Sparse Graphs

I've developed a graph clustering model for assigning destinations to vehicle routes, but my implementation is very slow. It takes about two days to process a graph with 400k nodes. My current ...
fume_hood_geologist's user avatar
0 votes
0 answers
103 views

Two mst in one graph, require exactly the same weights on the edgs?

I need to find two different minimum spanning tree in one graph, I wanted to know if it must be that for every weight of a edge that exists in the first minimum spanning tree there is a edge with the ...
TamarL's user avatar
  • 9
6 votes
1 answer
254 views

MST that crosses a graph cut exactly N times

Given two connected weighted graphs and a set of pairs of vertices that can "cross the river" between the two graphs, the task is to find an MST (minimum spanning tree) of a graph made of ...
tomashauser's user avatar
4 votes
2 answers
386 views

How to build a Minimum Spanning Tree given a list of 200 000 nodes?

Problem I have a list of approximatly 200000 nodes that represent lat/lon position in a city and I have to compute the Minimum Spanning Tree. I know that I need to use Prim algorithm but first of all ...
aaalloc's user avatar
  • 43
-2 votes
2 answers
1k views

What is a minimal-spanning subnet?

What is a minimal-spanning subnet? How do you find it for a given set of IPv4 addresses? I know the minimum spanning tree but what is the minimum spanning subnet? and how to find it by the given ipv4 ...
Himanshu Joshi's user avatar
0 votes
1 answer
53 views

Remove all symmetrical relations in an adjacency list based on a minimum spanning tree set

So say I have an undirected, weighted graph represented using an adjacency list: # Dict with key being source and value being list of connections made up of tuple of destination and cost ...
Aspect11's user avatar
  • 328
0 votes
1 answer
520 views

Proving the following claim for MST (Minimum Spanning Trees)?

I want to prove the following claim for undirected and connected graph, Spanning Tree (T) and weight function with real numbers: $T$ is a minimum spanning tree in $G=(V,E)$ iff for every edge $e=u-v$ ...
user avatar
0 votes
1 answer
152 views

Prim's MST implementation with priority queue error

My algorithm calculated the correct distances between points, but then updated some of the values to a smaller value in the nested for loop for the test case below. I suspect there's an error in the ...
Young42's user avatar
  • 83
2 votes
0 answers
145 views

Please provide a valid WRITE query

I try to run minimum spanning tree algorithm inside Spark using Neo4j Connector. But when I try to call it I get an error: Please provide a valid WRITE query. My code looks like this: val df = (1 to ...
ffdfgdffddf's user avatar
-1 votes
2 answers
803 views

Linear Time Algorithm to Find MST?

Given 2 Algorithms for a graph G=(V,E): One: Sort edges from lowest to highest weight. Set T = {} for each edge e in the previous order, check if e Union T doesn't have any cycles. If yes, Add e to T....
LOG's user avatar
  • 45
0 votes
1 answer
63 views

What is the logic behind this index in Kruskal's minimum spanning tree algorithm?

I don't understand why we are increasing e += 1 when the parents are not same. And why the while loop stops based on e's value? Why we need that index? def kruskal(self): i, e = 0, 0 ds = dst....
VRM's user avatar
  • 123
2 votes
0 answers
108 views

How to analyze all traces in a graph analyzed with minimum spanning trees?

The Minimum Spanning Tree algorithm (MST) allows to find the shortest possible connexion for all nodes. In Python, Scipy provides a package to analyze MST. I want to find a way to get the main traces ...
Ruthger Righart's user avatar
1 vote
1 answer
647 views

C# Prim's algorithm isn't generating maze correctly

I was trying to implement a C# version of the Java code given in this answer to generate a random maze, but my code doesn't quite generate the mazes correctly - it creates "isolated" wall ...
Jez's user avatar
  • 30.5k
1 vote
1 answer
216 views

Why can't edges be fewer than vertices in Graph theory?

Upon analyzing Kruskal's Algorithm, Kruskal's Algorithm is apparently considered to be E log E because "for an MST to exist, E can't be smaller than V so assume it dominates" However, the ...
Won Young Jung's user avatar
0 votes
1 answer
1k views

Prim's algorithm using heap or unsorted array?

There's a question in my CS class asking that if the graph is a sparse graph, which is n^2 >> m, whether unsorted list with O(n^2) is more efficient than the binary heap O((m+n)logn). I'm a ...
Elon Mask off's user avatar
0 votes
1 answer
435 views

Minimum cost to make connect all nodes in one partition of a weighted undirected bipartite graph

Given a weighted undirected bipartite graph between partition A and B, I'm trying to find the minimum cost to connect all nodes in partition A. It seems like I need to first find a Minimum Spanning ...
Dawei's user avatar
  • 1
0 votes
1 answer
213 views

True or False: For an undirected graph, for every vertex, its edge with minimum weight is in a minimum spanning tree

I think this is true. With consideration to Prim's algorithm, the minimum edge of a vertex is either already in a tree, or will be selected eventually. I also tried a lot of graph and they all seem ...
user avatar
2 votes
1 answer
1k views

Time complexity of Prim's MST algorithm problem

I have a graph problem where we have: There are exactly n vertices and n-1 edges. All vertices are connected with each other – i.e. the network consists of just one connected component. The network ...
Marcus F's user avatar
  • 545
1 vote
1 answer
382 views

How can I find an MST from all trees containing a given edge?

In a weighted undirected graph, I need to modify Kruskal's algorithm to find the MST conditional to the fact that it includes a given edge 'e' in O(m log n) time. How can I do that?
andie's user avatar
  • 45
0 votes
0 answers
35 views

A sub-optimal solution that does not guarantee that all MSTs are found in a reasonable time

The calculation of all MSTs of a graph is infeasible in practice. This is because the number of all MSTs has an upper bound of n power (n-2), where n is the number of nodes in the graph. Therefore ...
Elvissmog's user avatar
0 votes
1 answer
119 views

Getting nodes without edges (When the N is larger than 60)

First I generated an NxN matrix of zeros and ones using NumPy. After that, I generated a copy matrix from the previous matrix, I replaced the ones in the first matrix with the weight of the edges. ( ...
Yesin N. Serrid's user avatar
0 votes
1 answer
364 views

How to convert a minimum spanning tree to a path/route in Java?

I have a minimum spanning tree in Java. This is in a Graph class which has a list of Nodes, those Node classes have a list of Edge classes which have a boolean if they are in the MST or not. Example: ...
Banjer_HD's user avatar
  • 300
0 votes
2 answers
198 views

How is a cut lonely if there are often multiple edges crossing a cut in a connected undirected graph?

I'm learning the requirements for finding a minimum spanning tree for a connected, undirected graph with distinct edge costs. One of the requirements is that there must be no cycles created in the ...
julieb's user avatar
  • 43
3 votes
1 answer
265 views

Give minimum permutation weight for edges such that a given set of edge is the Minimum Spanning Tree

Question: Given a graph of N nodes and M edges, the edges are indexed from 1 -> M. It is guaranteed that there's a path between any 2 nodes. You need to assign weights for M edges. The weights are ...
unglinh279's user avatar
-1 votes
1 answer
117 views

Coding MST (4) in CPLEX

I'm trying to code MST4 in CPLEX, but because I'm new to code writing I have difficulty in doing it. I would really appreciate if anyone could help me. Thanks
minela boghossian's user avatar
1 vote
1 answer
565 views

Find weight of MST in a complete graph of two weight with given edges

I need to get the MST of a complete graph where all edges are defaulted to weight 3, and I'm also given edges that have weight 1. Here is an example 5 4 (N, M) 1 5 1 4 4 2 4 3 Resulting MST = 3 -> ...
JameEnder's user avatar
0 votes
0 answers
341 views

making kruskal's algorithm in c (segmentation fault)

In this code I want to make Kruskal's algorithm, which calculates a minimum spanning tree of a given graph. And I want to use min-heap and disjoint set at the code. To make time complexity of O(e log ...
chae yeon's user avatar
0 votes
0 answers
69 views

getting segmentation error on Kruskal algorithm for mst in gfg practice

vector<int> pr; vector<int> sz; vector<vector<int>> ans; void mset(int u) { pr[u] = u ; sz[u] = 1; } int fset(int u) { if(pr[u] == u) return u; ...
B G's user avatar
  • 1

1
2 3 4 5
13