Can we solve the Traveling Salesman Problem by finding the Minimum Spanning Tree?
The Minimum Spanning Tree problem asks you to build a tree that connects all cities and has minimum total weight, while the Travelling Salesman Problem asks you to find a trip that visits all cities with minimum total weight (and possibly coming back to your starting point).
If you're having trouble seeing the difference, in MST, you need to find a minimum weight tree in a weighted graph, while in TSP you need to find a minimum weight path (or cycle / circuit). Does that help?
It's the difference between
Finding an acyclic connected subgraph T of G with V(T) = V(G) and Weight(T) is minimal
and
Finding a cycle C in G such that V(C) = V(G) and Weight(C) is minimal
where Weight(X) = Sum of edges of X. As you can see these two problems are pretty different.
Yet, there is a relation between the two. If the graph weights satisfy the triangle inequality, one can use the MST to approximate the TSP within a factor of x2: compute the MST, then traverse it (from any root) and return the vertices in a pre-order. You can find the detailed analysis of this approximation (as well as other approximations) in The traveling salesman problem: An overview of exact and approximate algorithms by G Laporte - European Journal of Operational Research, 1992 - Elsevier.
Related
I know a few algorithms that are able to find the lowest cost path for directed graph (just as Dijkstra and Floyd).
Is there any algorithm that works for non-directed graphs?
My problem is: I need to find the lowest cost path from a to b passing through all vertexes (undirected graph).
My problem is: I need to find the lowest cost path from a to b passing
through all vertexes (non-oriented graph)
This is the Traveling Salesman Problem, which is NP-Hard, so there is no known efficient solution to it.
However, if the graph is fairly small, there are some techniques to solve it optimally (in exponential time), like Dynamic Programming.
In general, changing an undirected graph to a directed one is fairly easy and is done by changing an undirected edge {u,v} to two directed edges (u,v) and (v,u)
Provided you have nonnegative edge values, you could consider every edge in an undirected graph as two edges in a directed graph, one pointed to and from connected vertices. Then you could use one of many algorithms including the ones you listed.
I encounter this problem recently and I want to know whether it is NP-Complete or solvable in polynomial time:
Given a weighted bipartite graph G=(V,E) where V can be partitioned into two sets A and B and E is a set of edges connecting A and B. The weight of an edge (v,u) is denoted as w(v,u).
Do the following sequentially:
Pick a node v∈A,
remove all node u∈B for every (v,u)∈E and,
add the weight w(v,u) to the total score for every edges deleted.
The goal is to find the sequence of nodes v1,…,vn∈A that maximizes the total score.
I have searched for the bank of NP-Complete problems to find something possible can reduce to this problem but I haven't found anything useful yet. Any suggestions would be extremely helpful!
I have an undirected graph of locations in an indoor map.
When given a set of vertices , i want to find the shortest path which will cover all those vertices.
Graph contains 52 vertices and 150 - 250 Edges.
What is the best algorithm i can use to find the shortest path.
Please don't get confused that this is a Travelling Salesman Problem. It doesn't have to cover all the nodes.Only the given set of nodes.
As i've commented, this is a hard problem, so don't expect a polynomial time algorithm.
But if you're looking for an algorithm that you may be able to compute in acceptable time for the problem instances you mentioned, this might work:
Let G(V,E) be the original graph, let N be the set of nodes that must be visited.
1. Compute the shortest-path matrix M for the entire graph (|V|x|V| matrix that contains
the length of the shortest path between each two nodes).
2. Generate a new graph G`, containing N alone, with the distances between each
two nodes taken from the shortest-path matrix M.
3. Solve the Minimum Weight Hamiltonian Path Problem on G`.
Note that the "hardest" part here is the third part, which takes exponential time. but if the group N is not too big, you'll be able to solve it:
Bruteforce algorithm will let you solve problems where N contains about 11 nodes within seconds ( O(|N|!) complexity )
Dynamic Programming will let you solve problems where N contains about 20 nodes within seconds ( O(2^|N|*|N|^2) complexity.
You can basically apply any algorithm that solves the Minimum Weight Hamiltonian Path Problem to the third part, these algorithms are usually equivalent to TSP algorithms (the only difference between these problems is that in the TSP you return to the source node after visiting all the other nodes).
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.
I have an undirected, positive-edge-weight graph (V,E) for which I want a minimum spanning tree covering a subset k of vertices V (the Steiner tree problem).
I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which k vertices must be included in the MST.
Starting from the entire MST I could pare down edges/nodes until I get the smallest MST that contains all k.
I can use Prim's algorithm to get the entire MST, and start deleting edges/nodes while the MST of subset k is not destroyed; alternatively I can use Floyd-Warshall to get all-pairs shortest paths and somehow union the paths. Are there better ways to approach this?
There's a lot of confusion going on here. Based on what the OP says:
I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which k vertices must be included in the MST.
This is the Steiner tree problem on graphs. This is not the k-MST problem. The Steiner tree problem is defined as such:
Given a weighted graph G = (V, E), a subset S ⊆ V of the vertices,
and a root r ∈ V , we want to find a minimum weight tree which connects all the vertices in S to
r. 1
As others have mentionned, this problem is NP-hard. Therefore, you can use an approximation algorithm.
Early/Simple Approximation Algorithms
Two famous methods are Takahashi's method and Kruskal's method (both of which have been extended/improved by Rayward-Smith):
Takahashi H, Matsuyama A: An approximate solution for the Steiner problem in graphs. Math. Jap 1980, 24:573–577.
Kruskal JB: On the Shortest Spanning Subtree of a Graph and the Traveling Salesman Problem. In Proceedings of the American Mathematical Society, Volume 7. ; 1956:48–50.
Rayward-Smith VJ, Clare A: On finding Steiner vertices. Networks 1986, 16:283–294.
Shortest path approximation by Takahashi (with modification by Rayward-Smith)
Kruskal's approximation algorithm (with modification by Rayward-Smith)
Modern/More Advanced Approximation Algorithms
In biology, more recent approaches have treated the problem using the cavity method, which has led to a "modified belief propagation" method that has shown good accuracy on large data sets:
Bayati, M., Borgs, C., Braunstein, A., Chayes, J., Ramezanpour, A., Zecchina, R.: Statistical mechanics of steiner trees. Phys. Rev. Lett. 101(3), 037208 (2008) 15.
For an application: Steiner tree methods for optimal sub-network identification: an empirical study. BMC Bioinformatics. BMC Bioinformatics 2013 30;14:144. Epub 2013 Apr 30.
In the context of search engine problems, approaches have focused on efficiency for very large data sets that can be pre-processed to some degree.
G. Bhalotia, A. Hulgeri, C. Nakhe, S. Chakrabarti, and S. Sudarshan. Keyword Searching and Browsing in Databases using BANKS. In ICDE, pages 431–440.
G. Kasneci, M. Ramanath, M. Sozio, F. M. Suchanek, and G. Weikum. STAR: Steiner-tree approximation in relationship graphs. In ICDE’09, pages 868–879, 2009
The problem you stated is a famous NP-hard problem, called Steiner tree in graphs. There are no known solutions in polynomial time and many believe no such solutions exist.
Run Prim's algorithm on the restricted graph (k, E') where E' = {(x, y) ∈ V : x ∈ k and y ∈ k}). Constructing that graph takes O(|E|).