Minimum Weight Path - graph

"Given a connected undirected weighted graph, find the maximum weight of the edge in the path from s to t where the maximum weight of the edges in the path is the minimum."
This seems like a Floyd–Warshall algorithm problem. Is there an approach faster than O(V^3)?

I submit that a breadth first search (BFS) to determine whether s is connected to t by any path can run in O(V) time, since each vertex need only be visited once.
I propose therefore, that the solution to this problem is to sort the edges by weight, and then
while the BFS succeeds in finding a path from s to t
remove the highest weighted edge from the graph
The last edge to be removed before the BFS fails is the maximum weighted edge that you're looking for.
Total running time is O(E log E) to sort the edges by weight, plus O(VE) to run the BFS until removing an edge disconnects the graph.

Related

Single source shortest path using BFS for a undirected weighted graph

I was trying to come up with a solution for finding the single-source shortest path algorithm for an undirected weighted graph using BFS.
I came up with a solution to convert every edge weight say x into x edges between the vertices each new edge with weight 1 and then run the BFS. I would get a new BFS tree and since it is a tree there exists only 1 path from the root node to every other vertex.
The problem I am having with is trying to come up with the analysis of the following algorithm. Every edge needs to be visited once and then be split into the corresponding number of edges according to its weight. Then we need to find the BFS of the new graph.
The cost for visiting every edge is O(m) where m is the number of edges as every edge is visited once to split it. Suppose the new graph has km edges (say m').
The time complexity of BFS is O (n + m') = O(n + km) = O(n + m) i.e the Time complexity remains unchanged.
Is the given proof correct?
I'm aware that I could use Dijkstra's algorithm here, but I'm specifically interested in analyzing this BFS-based algorithm.
The analysis you have included here is close but not correct. If you assume that every edge's cost is at most k, then your new graph will have O(kn) nodes (there are extra nodes added per edge) and O(km) edges, so the runtime would be O(kn + km). However, you can't assume that k is a constant here. After all, if I increase the weight on the edges, I will indeed increase the amount of time that your code takes to run. So overall, you could give a runtime of O(kn + km).
Note that k here is a separate parameter to the runtime, the same way that m and n are. And that makes sense - larger weights give you larger runtimes.
(As a note, this is not considered a polynomial-time algorithm. Rather, it's a pseudopolynomial-time algorithm because the number of bits required to write out the weight k is O(log k).)

finding maximum weight subgraph

My graph is as follows:
I need to find a maximum weight subgraph.
The problem is as follows:
There are n Vectex clusters, and in every Vextex cluster, there are some vertexes. For two vertexes in different Vertex cluster, there is a weighted edge, and in the same Vextex cluster, there is no edge among vertexes. Now I
want to find a maximum weight subgraph by finding only one vertex in each
Vertex cluster. And the total weight is computed by adding all weights of the edges between the selected vertex. I add a picture to explain the problem. Now I know how to model this problem by ILP method. However, I do not know how to solve it by an approximation algorithm and how to get its approximation ratio.
Could you give some solutions and suggestions?
Thank you very much. If any unclear points in this description,
please feel free to ask.
I do not think you can find an alpha-approx for this problem, for any alpha. That is because if such an approximation exists, then it would also prove that the unique games conjecture(UGC) is false. And disproving (or proving) the UGC is a rather big feat :-)
(and I'm actually among the UGC believers, so I'd say it's impossible :p)
The reduction is quite straightforward, since any UGC instance can be described as your problem, with weights of 0 or 1 on edges.
What I can see as polynomial approximation is a 1/k-approx (k the number of clusters), using a maximum weight perfect matching (PM) algorithm (we suppose the number of clusters is even, if it's odd just add a 'useless' one with 1 vertex, 0 weights everywhere).
First, you need to build a new graph. One vertex per cluster. The weight of the edge u, v has the weight max w(e) for e edge from cluster u to cluster v. Run a max weight PM on this graph.
You then can select one vertex per cluster, the one that corresponds to the edge selected in the PM.
The total weight of the solution extracted from the PM is at least as big as the weight of the PM (since it contains the edges of the PM + other edges).
And then you can conclude that this is a 1/k approx, because if there exists a solution to the problem that is more than k times bigger than the PM weight, then the PM was not maximal.
The explanation is quite short (lapidaire I'd say), tell me if there is one part you don't catch/disagree with.
Edit: Equivalence with UGC: unique label cover explained.
Think of a UGC instance. Then, every node in the UGC instance will be represented by a cluster, with as many nodes in the cluster as there are colors in the UGC instance. Then, create edge with weight 0 if they do not correspond to an edge in the UGC, or if it correspond to a 'bad color match'. If they correspond to a good color match, then give it the weight 1.
Then, if you find the optimal solution to an instance of your problem, it means it corresponds to an optimal solution to the corresponding UGC instance.
So, if UGC holds, it means it is NP-hard to approximate your problem.
Introduce a new graph G'=(V',E') as follows and then solve (or approximate) the maximum stable set problem on G'.
Corresponding to each edge a-b in E(G), introduce a vertex v_ab in V'(G') where its weight is equal to the weight of the edge a-b.
Connect all of vertices of V'(G') to each other except for the following ones.
The vertex v_ab is not connected to the vertex v_ac, where vertices b and c are in different clusters in G. In this manner, we can select both of these vertices in an stable set of G' (Hence, we can select both of the corresponding edges in G)
The vertex v_ab is not connected to the vertex v_cd, where vertices a, b, c and d are in different clusters in G. In this manner, we can select both of these vertices in an stable set of G' (Hence, we can select both of the corresponding edges in G)
Finally, I think you can find an alpha-approximation for this problem. In other words, in my opinion the Unique Games Conjecture is wrong due to the 1.999999-approximation algorithm which I proposed for the vertex cover problem.

Pathfinding: broadest path

I have a networkx graph in which a cost has been assigned to each edge, and I want to compute the path from source to target nodes that represents broadest bottleneck instead of shortest path. So, highest edge cost should be minimized instead of the sum of individual edge costs. What algorithm should I use?

Finding shortest path in the dynamic graph

Here is my problem: I have a directed weighted graph with a substantial amount of vertices (few thousands), no cycles, in fact, it includes a starting node, a final node and a grid (m*n) between them, where edges can be directed from the left to the right only.
The weights of the edges depend on the path in which they are included (for example, if the path includes v.15, then the weights of several edges change).
I tried to get all possible paths and then calculate their final sum post factum, but that turned out to be very inefficient method due to the number of paths. Is there an effective method which allows to find shortest paths in these kind of graphs? Thanks.

Graph shortest path?

I am facing which I believe is a kind of shortest path problem on a graph.
I need to find shortest path from node A to B, considering all edges have positive weight for connected vertexes, ∞ for not connected ones.
Vertexes have variable positive weightes.
The cost of a path is the weight of the vertex with maximum weight considering all vertexes involved in that path.
Should I apply Dijkstra in this situation, and if so how, considering that the weight of each Vertex changes depending on the previous vertexes visited?
Can you point me on how to tackle this problem otherwise?
I cant understand if you should consider the weights of the edges,because you said that you want the path with the max/min weight on a vertice possible,from A to B.
My solution for that is to convert every weight on vertex,to a weight on edge , just like in the image:
now you want to find the path from A to B where the the biggest weight on edge is min/max.
you can use MST algotirhm for this,because you dont care about the path lenght,but only the max/min edge cost.

Resources