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.
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.
I'm taking the Algorithms: Design and Analysis II class, one of the questions asks:
Assume that P ≠ NP. Consider undirected graphs with nonnegative edge
lengths. Which of the following problems can be solved in polynomial
time?
Hint: The Hamiltonian path problem is: given an undirected graph with
n vertices, decide whether or not there is a (cycle-free) path with n
- 1 edges that visits every vertex exactly once. You can use the fact that the Hamiltonian path problem is NP-complete. There are relatively
simple reductions from the Hamiltonian path problem to 3 of the 4
problems below.
For a given source s and destination t, compute the length of a shortest s-t path that has exactly n - 1 edges (or +∞, if no such path
exists). The path is allowed to contain cycles.
Amongst all spanning trees of the graph, compute one with the smallest-possible number of leaves.
Amongst all spanning trees of the graph, compute one with the minimum-possible maximum degree. (Recall the degree of a vertex is the
number of incident edges.)
For a given source s and destination t, compute the length of a shortest s-t path that has exactly n - 1 edges (or +∞, if no such path
exists). The path is not allowed to contain cycles.
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-Complete 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. Thus, problem 2 is NP-Complete.
Problem 3 is NP-Hard; here is a paper that proves that.
That means, between 1 and 4, one is NP-Complete, another is in P. It seems like problem 4 reduces trivially to the the Hamiltonian path problem, but I'm not able to understand how having a cycle makes it solvable? Or is it the other way?
For the first one you can use Dijkstra to get shortest even and odd distances possible. To this end for every vertex you need to store not a single minimum number, but two of them. One is minimum weight of an odd path, another one is for minimum weight of an even path. After you have these two lengths you can easily increase path length by even number of edges if cycles are allowed. So, the first problem is from P. Step-be-step algorithm would be:
Find shortest even and odd length paths.
Increase length of one of these paths which has the same parity as n-1 to n-1 by adding cycle of length 2 required number of times.
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.
Claim: If all the edges weights in a graph are distinct, then there is a unique shortest path tree. Either give a convincing argument that the claim is true or give a counterexample.
If you have MST then there is a unique path from every two vertices which makes the shortest path tree senseless. I assume you meant the result is a MST. However, this is not true. Shortest path trees are different from minimum spanning trees for the same graph and even for the same root. Shortest Path tree rooted on vertex v is usually the result of applying Dijkstra's algorithm over v.
In general, uniqueness for trees over graphs is hard to be believed in unless strict requirements were given (like the new weights equal old ones +1). #rici gave a counterexample with a polytree structure. Here is another counterexample for undirected graphs. Both trees are shortest path trees rooted at A. Note that:
While both are shortest path trees, their total cost differ.
Both are spanning trees but neither one of them is a minimum.
If I understand the question, correctly:
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.