Shortest path spanning tree with 1 weighted edges vs MST - algorithm

I currently studying about graphs and their algorithms, and i noticed a question which i don't know to to exactly prove:
If we have a connected, undirected graph G=(V,E), and every edge is with weight=1,is it true to say that every spanning tree that built from the shortest paths from the root, is a minimum spanning tree?
I ran some examples in http://visualgo.net/sssp.html and is seems for me that the answer for this question is true, but someone can show me how can i prove this?
and another question that crossed my mind, does the other direction is also true?

Every tree has exactly n - 1 edges. Since all weights are equal to 1, every spanning tree of G has a total weight of n - 1. It is also true for the minimal spanning tree. So the answer is yes.

TLDR: Not Necessarily
Consider the triangle graph with unit weights - it has three vertices x,y,z, and all three edges {x,y},{x,z},{y,z} have unit weight. The shortest path between any two vertices is the direct path. Agree?However, to satisfy the condition of a MST in the graph, you have to put together a set of 2 edges connecting the 3 vertices. Say {x,y}, {y,z} for example. This does not represent the shortest path between any pair of vertices.
Hence, your proposition is false :)

Related

Relation between Dijkstra and MST

This question came to my mind when I see this question. For simplicity, we can limit our discussion to undirected, weighted, connected graphs. It is clear that Dijkstra cannot guarantee to produce a MST if we choose an arbitrary node from a graph as the source. However, is it guaranteed that there must exist one node in an undirected, weighted, connected graph, which will produce a MST for the graph if we choose it as the source and apply Dijkstra's algorithm? Maybe you can give a proof or a counterexample. Thanks!
However, is it guaranteed that there must exist one node in an
undirected, weighted, connected graph, which will produce a MST for
the graph if we choose it as the source and apply Dijkstra's
algorithm?
Nope, Dijkstra's algorithm minimizes the path weight from a single node to all other nodes. A minimum spanning tree minimizes the sum of the weights needed to connect all nodes together. There's no reason to expect that those disparate requirements will result in identical solutions.
Consider a complete graph where the sum of the weight of any two edges exceeds the weight of any single edge. That forces Dijkstra to always select the direct connection as the shortest path between two nodes. Then, if the lowest weight edges in the graph don't all originate from a single node, the minimum spanning tree won't be the same as any of the trees that Dijkstra will produce.
Here's an example:
The minimum spanning tree consists of the three edges with weight 3 (total weight 9). The trees returned by Dijkstra's algorithm will be whichever three edges connect directly to the source node (total weight 10 or 11).

Finding spanning tree with maximum minimum degree

Given a connected undirected graph, the problem of finding the spanning tree with the minimum max degree has been well-studied (M. F¨urer, B. Raghvachari, "Approximating the minimum degree spanning tree to within one from the optimal degree", ACM-SIAM Symposium on Discrete Algorithms (SODA), 1992). The problem is NP-hard and an approximation algorithm has been described in the reference.
I am interested in the following problem - given a connected undirected graph G = (V1,V2,E), find the spanning tree with the maximum min degree over all internal nodes (non-leaf nodes). Can someone please tell me if this problem has been studied; is it NP-hard or does there exist a polynomial-time algorithm for solving it? Also, the graph can be considered to be bipartite for convenience.
As noted in Evgeny Kluev's comment, the leaves of a (finite) tree have degree 1. (Else, cycles would exist and the structure would not be a tree.)
If instead you mean to find a spanning tree with a node of maximum degree, from among all possible spanning trees on a connected undirected graph G, then just form a spanning tree whose root R is a node M of G with maximal degree among all the nodes of G, and all neighbors of M are children of R.
It looks like exact cover by 3-sets can be reduced to this problem. Represent the 3-sets by vertices of degree 4, each with 3 edges connecting it to 3 nodes representing its elements in the original problem instance. The additional 4th edge connects all the "3-set" nodes to a single vertex V.
This graph is biparite - every edge is between a "3-set" node and an "element" node (or V). Now this graph has a spanning tree of max min degree = 4 if and only if the original problem has a solution.
Obviously there need to be enough of the 3-sets so that the node V doesn't lower the max min degree of the tree, but this limit doesn't change the NP-hardness of the problem.

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 spanning tree of the graph is unique. Is
the path between a pair of vertices in a minimum spanning tree of an
undirected graph necessarily the shortest (minimum weight) path?
My Answer is
(a)
No, for example, for graph 0, 1, 2, 0-1 is 4, 1-2 is 2, 2-0 is 5, then 0-2’s true shortest path is 5, but the mst is 0-1-2, in mst, 0-2 is 6
(b)
My problem comes into this (b).
I don't understand how whether the MST is unique can affect the shortest path.
First, my understanding is that when the weights of edges are not distinct, multiple MST may exist at the same time, right?
Second, even if MST is unique, the answer of (a) above still applies for (b), right?
So lets take a look at a very simple graph:
(A)---2----(B)----2---(C)
\ /
---------3----------
The minimum spanning tree for this graph consists of the two edges A-B and B-C. No other set of edges form a minimum spanning tree.
But of course, the shortest path from A to C is A-C, which does not exist in the MST.
EDIT
So to answer part (b) the answer is no, because there is a shorter path that exists that is not in the MST.
Regarding (a), I agree.
Regarding (b), for some graphs, there may be more minimal spanning trees with the same weight. Consider a circle C3 with vertices a,b,c; weights a->b=1, b->c=2, a->c=2. This graph has two MSTs, {a-b-c} and {c-a-b}.
Nevertheless, your counterexample still holds, because the MST is unique there.
AD a)
a very simple visualization would be:
MSP in a graph:
Shortest Path between A and C:
AD b)
I guess that the uniqueness of MSP means that there is only 1 MSP MSP in a graph. So:
First) Yes, if the weights of edges are not distinct, multiple MST may exist at the same time. In case of our graph, another possible MSP would include arc D-C instead of A-B (as an example).
Second) The uniqueness of MST does not influence the answer for a). As an example:
Isn't the MST related to the start node?!
Then he is trying to get the shortest path from the MST start node. Therefore, yes, the shortest path is given by the MST starting from A!

Minimum spanning tree in a graph with multiple root vertices

I would like to know if there is an algorithm which computes a minimum spanning tree (optimum branching) in a directed graph given a set of root vertices between all of these root vertices, but not only one root vertex and all other vertices in a graph.
Given a set of root vertices [1,4,6] and a graph G like the one on the following picture:
...the algorighm should return something like a green sub-graph on the same picture.
I would like to get such an MST that connects all the root vertices provided to the algorithm. I tend to think that the result of the would-be algorithm is a sub-graph of the graph G which contains all root vertices and some other vertices from G.
Notes:
I know that there is no MST for a directed graph, but there is Chu–Liu/Edmonds algorithm.
I guess that a result of such an algorithm (if it is actually possible) will return an optimum branching, which includes some vertices of a graph along with all root vertices.
Minimum Spanning Trees are supposed to span all the vertices. I think you might be actually dealing with a Steiner Tree problem, given that you only need to connect a subset of them. Unfortunately, the traditional Steiner tree problem with undirected edges is already NP complete so you have a tough road ahead of you.

Single shortest path of an acyclic undirected disconnected graph

Is there a graph algorithm that given a start(v) and an end(u) will find a shortest path through the given set of edges, but if u is a disconnected vertex, it will also determine the shortest path to add missing edges until u is no longer disconnected?
I have a pixel matrix where lines are made of 255's(black) and 0's(white). lines(255) can have breaks or spurs and I must get rid of both. I could have a pixel matrix forest with say 7 or so trees of black pixels. I need to find the true end points of each tree, find the single shortest path of each tree, then union all skew trees together to form 1 single line(ie, a single shortest path from the furthest 2 end points in the original matrix). all edge weights could be considered 1.
Thanks
How about running Dijkstra's algorithm and if disconnected, connect v and u? What's your criteria for "best place to add a missing edge?" Do edges have weights (like distance)?
Edit:
For one idea of "the best place," you could try the path that has minimal sum of shortest paths between all connected pairs. Floyd–Warshall algorithm can be used to find shortest paths between all pairs. So, run Floyd-Warshall for each node in v's tree and u.
Your problem isn't well defined for disconnected graphs. I can always add and edge between v and u.
If you meant that given an acyclic undirected disconnected graph, actually known as a forest, and given a subset of edges as a subgraph, can you find the shortest path between vertices, than this problem is trivial since if there is a path in the full graph, there is one path only.
If this is a general graph G, and you are talking about a forest subgraph G', than we need more info. Is this weighted? Is it only positive weights? If it is unweighted, do some variant of Dijksta. Define the diameter of a tree to be the length of the longest path between two leaves (this is well defined in a tree, since ther is only one such path). Let S be the sum of the diameters of all the trees in G', then set the weight all edges out of G' to 2S, then Dijkstra's algorithm will automatically prefer to step through G', stepping outside G' only when there is no choice, since walking through G' would always be cheaper.
Here you have following scenarios:
case:1. (all edges>0)
Negate all edges
find the longest path in graph using this:
https://www.geeksforgeeks.org/longest-path-undirected-tree/
negate the final result
case2: edges might be or might not be negative
Read Floyd–Warshall algorithm for this

Resources