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.
Related
hi i am doing the following algorithm. here is the question's picture
https://i.stack.imgur.com/qLyBC.png
and my answer for the following question is
I-f
f-g
f-g
g-d
d-a
g-c
a-h
a-b
is this path the right way for the minimum spanning tree? if not which other vt do i have to take?
Your final answer seems to be correct. (Aside from that you wrote f-g twice instead of f-e, f-g).
You can verify that its a spanning tree by running some other algorithm to find a spanning tree (such as Kruscal's).
Note: any two spanning trees have the same weight, and in particular they shpuld have the same number of edges for each weight (allowing you to verify your solution by running another spanning tree algorithm you might be more familiar with, and checking if the weights are similar)
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.
How do you prove that that the maximum spanning tree of an undirected graph will contain the path that is the widest path between any two vertices A and B in the graph?
I have tried thinking about the proof for Kruskal's algorithm with an edit so it produces the maximum spanning tree but I do not see why the maximal spanning tree must contain the edges in the widest path especially if there are multiple widest paths.
Proofs about optimality are often by contradiction. Here you'd set yourself up to find one by saying
Suppose there are vertices A and B with a widest path between them containing at least one edge not in any maximum spanning tree of the graph.
Now you must show that the existence such an edge leads to the desired contradiction. One clear path would be to show that this edge can be used to construct a new spanning tree of weight greater than any of the graph's maximum spanning trees. Therefore they weren't maximum after all.
The existence of a contradiction shows that the hypothetical widest path from A to B doesn't exist. Therefore the proof is at hand.
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 ...
I have to create a solution for a weighted undirected graph, passing through all the nodes, with a total minimum cost. Several paths, with no defined starting nodes, should end up and meet at one intersecting node. The number of the paths, and the number of the nodes included in a path are not pre-determined. The nodes can be passed more than once.
What kind of problem am I dealing with, possible algorithms as solution?
I suppose it should be a variation of a Minimum spanning tree (meaning using the intersection node as a starting point for the paths in stead of ending point)
It's called Minimum Cost Hamiltonian Circuit problem.
Here you can read more about it.
It is a tree you are looking for and the problem is Minimum Spanning Tree-- MST: building a tree that spans all the nodes in graph and the cost of edges on the tree is minimum possible. It is a polynomial problem. Prim and Kruskal each have well-known algorithms for the solution.
See http://en.wikipedia.org/wiki/Kruskal's_algorithm for Kruskal's algorithm.
Note: the problem is NP-complete when the tree is supposed to span a given proper subset of nodes instead of all nodes in the graph. This time it is known as the Steiner Minimal Tree problem.