I am having trouble coming up with a polynomial time algorithm to solve the following problem:
Let πΊ=(π,πΈ) be an undirected and unweighted graph with π vertices. Let π_1,π_2,...,π_π be π=πβ1 distinct spanning trees of πΊ. Find a polynomial time algorithm that finds a spanning tree
π=(π,πΈ_π) in πΊ that contains at least one edge from each spanning tree π_π.
I would really appreciate any help on this!
Spanning trees have matroid structure. Therefore the following greedy algorithm works: starting with an empty forest, for each input spanning tree, extend the forest by any one tree edge that does not create a cycle. Correctness follows more or less directly from the augmentation property and the definition of independence.
Here is a basic solution.
//if the graph is given in input:
// If any bridge exists in the graph:
// return any spanning tree from the list of input spanning trees
while the size of result set is less than |V|-1:
for every tree in the list of spanning trees:
for every edge in the tree:
if edge is not a part of result set:
if adding this edge to the result set doesn't form a cycle:
add the edge to result set
break
if size of result set is V-1:
break
Size of list of spanning trees < |V|-1: while loop is required
Size of list of spanning trees > |V|-1: a proof would be required that "the result set returned by above algorithm includes at least one edge from all the remaining trees in the list of spanning trees". I'll try this proof at leisure.
If for the given graph |E| < 2*(|V|-1) or the size list of spanning trees < |V|, then the above algorithm definitely works.
An interesting case is when |E| >= 2*(|V|-1). As shown in the image below, for some input list of spanning trees L, say the set of green edges is the result set returned by the above algorithm. A spanning tree of Blue edges could be formed without using any of the green edges.
Just posted this answer so that it works as some basic ground work for people trying to answer this question. Otherwise, could be treated as brute force solution.
Related
write an algorithm to find a spanning tree that has the maximum number of leaves.
Write an algorithm to find a spanning tree with minimum number of nodes.
I am yet not able to come up with a solution for the following questions.
For the first part what I thought is to find the vertex with the highest degree and place it in the second last level such that the last level gets the maximum number of leaves.
Finding a spanning tree of a graph with maximum number of leaves is an NP-Complete problem. There is a reduction from the Dominating Set Problem which is NP-Complete.
Finding a spanning tree of a graph with minimum number of leaves is also an NP-Complete problem. Suppose if the graph has a Hamiltonian path then the graph has a spanning tree with just two leaves. Thus finding a spanning tree of a graph with minimum number of leaves is equivalent to finding whether a graph has a Hamiltonian path or not.
So for both the problems you need to develop approximation algorithms.
So my problem is the following:
I have an undirected (complete) weighted graph G=(V,E), and I would like to generate all the possible spanning trees with minimum number of leaves, i.e. with minimum number of vertices of degree 1. Let's call this kind of trees MIN_LEAF.
Possibly, I would like to directly generate, among all trees with minimum number of leaves, the one which has also the minimum total weight (please note that this is not necessarily a minimum spanning tree).
Is the problem of deciding if a tree T is a MIN_LEAF for a given graph G NP-complete?
If so, I wonder if some kind of heuristic algorithm exists (greedy or local search) which can at least give an approximate solution for this problem.
Thanks in advance.
The first problem you described - finding a spanning tree with the fewest number of leaves possible - is NP-hard. You can see this by reducing the Hamiltonian path problem to this problem: notice that a Hamiltonian path is a spanning tree of a graph and only has two leaf nodes, and that any spanning tree of a graph with exactly two leaf nodes must be a Hamiltonian path. That means that the NP-hard problem of determining whether a Hamiltonian path exists in a graph can be solved by finding the minimum-leaf spanning tree of the graph: the path exists if and only if the minimum-leaf spanning tree has exactly two leaves. The second problem you've described contains that first problem as a special case and therefore is going to also be NP-hard.
A quick Google search turned up the paper "On finding spanning trees with few leaves", which seems like it might be a good starting point for approximation algorithms (they have a 2-approximation for arbitrary graphs) and further reading on the subject.
First please note that this question is NOT asking about MST, instead, just all possible spanning trees.
So this is NOT the same as finding all minimal spanning trees or All minimum spanning trees implementation
I just need to generate all possible spanning trees from a graph.
I think the brute-force way is straight:
Suppose we have V nodes and E edges.
Get all edges of the graph
Get all possible combinations of V-1 out of E edges.
Filter out non-spanning-tree out of the combinations (for a spanning tree, all nodes inside one set of V-1 edges should appear exactly once)
But I think it is too slow when facing big graph.
Do we have a better way?
Set the weight of all edges to the same value, then use an algorithm to find all minimum spanning trees. Since all spanning trees have |V|-1 edges and all edge weights are equal, all spanning trees will be minimum spanning trees.
I've become interested in this question, and have yet to find a really satisfactory answer. However, I have found a number of references: Knuth's Algorithms S and S' in TAOCP Volume 4 Fascicle 4, a paper by Sorensen and Janssens, and GRAYSPAN, SPSPAN, and GRAYSPSPAN by Knuth. It's too bad none of them are implementations in a language I could use ... I guess I'll have to spend some time coding these ...
Yes this is homework. I was wondering if someone could explain the process of Sollin's (or BorΕ―vka's) algorithm for determining a minimum spanning tree. Also if you could explain how to determine the number of iterations in the worst case, that would be great.
On a top level, the algorithm works as follows:
Maintain that you have a number of spanning trees for some subgraphs. Initially, every vertex of the graph is a m.s.t. with no edges.
In each iteration, for each of your spanning trees, find a cheapest edge connecting it to another spanning tree. (This is a simplification.)
The worst case in terms of iterations is that you always merge pairs of trees. In that case, the number of trees you have will halve in each iteration, so the number of iterations is logarithmic in the number of nodes.
Also note that there is a special trick involved in choosing the edges to add: if you were not careful, you might introduce a circle when tree A connects to tree B, tree B connects to tree C and tree C connects to tree A. (This can only happen if all three edges chosen have the same weight. The trick is to have an arbitrary but fixed tie-breaker, like a fixed order of the edges.)
So there, that's my back-of-index-card overview.
I'm using the layman's terminology.
First select a vertex
Check all the edges from that vertex and select one with the minimum
weight
Do this for all the vertices ( some edges may be selected more than
once)
You will get connected components.
From these connected components select one edge with minimum weight.
Your spanning tree with minimum weight will be formed
Is there any applicable approach to find two disjoint spanning trees of an undirected graph or to check if a certain graph has two disjoint spanning trees
This is an example of Matroid union. Consider the graphic matroid where the basis are given by the spanning trees. Now the union of this matroid with itself is again a matroid. Your question is about the size of the basis of this matroid. (whether there exist a basis of size $2(|V|-1)$.
The canonical algorithm for this is Matroid partitioning algorithm. There exist an algorithm which does does the following: It maintains a set of edges with a partitioning into two forests. At each step given a new edge $e$, it decides whether there exist a reshuffling of the current partition into a new partition such that the new edge can be added to the set and the partition remains independent. And if not, it somehow will provide a certificate that it cannot.
For details look at a course in Comb. Optimization or the book by Schriver.
Not sure it helps much in the applicable side but Tutte [1961a] and Nash-Williams [1961] independently characterized graphs having k pairwise edge-disjoint spanning trees:
A graph G has k pairwise edge-disjoint spanning trees iff for every partition of the vertices of G into r sets, there are at least k(r-1) edges of G whose endpoints are in different sets of the partition.
Use k=2 and it may give you a lead for your needs.
According to A Note on Finding Minimum-Cost Edge-Disjoint Spanning Trees, this can be solved in O(k2n2) where k is the number of disjoint spanning trees, and n is the number of vertices.
Unfortunately, all but the first page of the article is behind a paywall.
Assuming that the desire is to find spanning trees with disjoint edge sets, what about:
Given a graph G determining the minimum spanning tree A of G.
Defining B = G - A by deleting all edges from G that also lie in A.
Checking if B is connected.
The nature of a minimum spanning tree somehow makes me intuitively believe that choosing it as one of the two spanning trees gives you maximum freedom in constructing the other (that hopefully turns out to be edge disjunctive).
What do You guys think?
edit
The above algorithm makes no sense as a spanning tree is a tree and therefore needs to be acyclic. But there is no guarantee that B = G - A is acyclic.
However, this observations (thx#Tormer) led me to another idea:
Given a graph G determine the minimum spanning tree A of G.
Define B = (V[G], E[G] \ E[A]) where V[G] describes the vertices of G and E[G] describes the edges of G (A respectively).
Determine, if B has a spanning tree.
It could very well be that the above algorithm fails although G indeed has two edge disjunctive spanning trees - just no one of them is G's minimum spanning tree. I can't judge this (now), so I'm asking for Your opinion if it's wise to always chose the minimum spanning tree as one of the two.