Finding shortest path contaning exactly one negative edge in a graph - graph

I am given a directed graph with a weight function and a vertex s.
My goal is to find for any other vertex v, the shortest path from s to v that goes through exactly one negative edge. The time complexity of the algorithm should be O(|E| + |V|*log|V|), so guess I need to use Dijkstra's algorithm somehow.
I am guessing that I need to translate my given graph somehow to a new graph with non-negative weights that a shortest path from s to v in this graph will be equivalent to the required shortest path in the given graph.. or maybe I need to modify Dijkstra's algorithm somehow??
I tried to think about it a little, don't have any ideas right now... :(

Related

Kth shortest path in undirected graph

Is there any way with polynomial complexity(or better than that) to get kth or k shortest path of an undirected graph?
or can Yen's k shortest path algorithm modified for undirected graphs?
Try to find the permutations of paths from source vertex to final vertex (taking all vertex atleast once) upto k permutations but this would also mean if the total permutations of paths from source vertex to final vertex (taking all vertex atleast once) are finite but that wouldnt be the case as in case of NP hard problems. if you can find this heuristic in polynomial time then you can select kth shortest path. so apply brute force dfs bfs then find the shortest path via dynamic programming and compare your permutations with kth case

Optimal meeting point in an directed graph having 2 starting vertices

What algorithm should I use if in a directed graph I want to find the shortest paths, having 2 starting vertices, so that the paths meet and both have the minimum distance for this to happen.
I would do an All-Pairs-Shortest-Path, find common endpoints, and then find the minimum of (distance(vertex1,endpoint)+distance(vertex2,endpoint)) for all possible endpoints
I would use Dijkstra's to get minimal distance trees for both starting vertices, then add the two distance vectors together and take the minimum. C.B.'s answer is fine, but you don't need the shortest distances between all pairs, so there's some redundant work there.

The most vital edge on the shortest path

I have this question form the Sedgewick's course on algorithms: "Critical edge. Given an edge-weighted digraph, design an E*log(V) algorithm to find an edge whose removal causes the maximal increase (possibly infinite) in the length of the shortest path from s to t. Assume all of the edge weights are strictly positive. (Hint: compute the shortest path distances d(v) form s to v and consider the reduced costs c′(v,w)=c(v,w)+d(v)−d(w) ≥ 0.)"
I've read on the internet that three (3) guys in 1989 came up with an algorithm of complexity O(E + V*log(V)) what required advanced data structures, and I think it was on a graph (not digraph). If it got three advanced computer scientist to develop this algorithms, is not it too much of a problem for an introductory course? But maybe it is much easier for just O(E*log(V)).
Can you help me to solve it? I don't understand the hint given in the question.
Here is a sketch of an algorithm to find the critical edge on a shortest path, based on Sedgewick's hint.
First, the reduced cost c′(v,w)=c(v,w)+d(v)−d(w) corresponds to the increase in the length of the shortest path from s to w, when going through v just before w. (If v is in the shortest path from s to w then this increase is 0.) (Indeed d(v) is the length of the shortest path from s to v and c(v, w) the cost to go from v to w.)
Suppose the shortest path from s to t is (s, ..., v, t) and that we remove the last edge (v, t). Then the increase in the length of the shortest path from s to t equals the minimum of the c'(u, t) for all in-edges (u, t), with u != v.
Suppose u is such that c'(u, t) is the minimum (still u != v). Then follow the shortest path from s to u backward, until you reach a vertex, say w, belonging to the shortest path from s to t (without any removed edge). The shortest path from s to t is something like (s, ..., w, ..., v, t).
Observe that if you remove any edge between w and t, you will get a maximum increase of c'(u, t) int the shortest path. Indeed, in case one of the edges between w and t is missing, it suffices to go from w to t through the vertex u. On the other hand, note that removing the last edge (v, t) will cause exactly this increase.
Now, just iterate with w what was done with t. Find a vertex x such that c'(x, w) is mininum and x is not on the shortest path. Follow the shortest path from s to x backward until you reach a vertex belonging to the shortest path from s to w.
Once you reach s then you're able to determine which vertex to remove to cause the maximum increase in the lenght of the shortest path.
This is a confusing question, I agree. Here are some my thoughts about it.
The "reduced cost" term and definition is used when reducing the A* search algorithm to Dijkstra's algorithm by replacing the original cost with the reduced cost:
c′(v,w) = c(v,w) - h(v) + h(w) = c(v,w) - (h(v) - h(w)) > 0
The h(v) - h(w) part is a drop of a heuristic function, which should not be more than the edge cost in case of consistent (monotonic) heuristic, thus the reduced cost is still greater than 0 (see slides 14 and 15 here)
It looks like Sedgewick suggests using the original distance function (d(v)) as a consistent heuristic when searching for the new/replacement shortest path in G' which is the same as the original G, but with one removed edge along the original shortest path from s to t. Personally, I don't see how it might help solving the most vital edge problem in O(ElogV) though.
There is also a similar problem: find all downward and upward critical edges in a graph. By definition, decreasing a cost of downward critical edge decreases the overall SP cost. Increasing a cost of upward critical edge increases the overall SP cost. All critical edges can be found in O(ElogV), see ch.8 here. But this does not answer the question what edge is the most critical (causes the max SP increase when removed).
As you noted, the most vital edge problem was solved by Malik, Mittal and Gupta (1989) in
O(E + V*log(V)) time. I have not found the original MMG paper, but this presentation explains it quite well. As far as I can see, it can be solved with a priority queue, no specific data structures required.
Sorry for not actually answering the original question (solution for most vital edge in a digraph using reduced costs), but still hoping that the links and thoughts above might be useful for someone. I would be happy to see the solution meant by Sedgewick.

Finding a shortest cycle

Basically, I need to have a shortest path in a graph that covers all of the vertices and returns to the source. Repetition of any vertex is ok so long as it is the shortest path.
My algorithm starts from the source. I run a dijkstra algorithm to find the shortest path. Then I choose the smallest weighted unreached vertex and run the dijkstra again as the chosen vertex as the source and keep doing it until all vertices are done. Then from the last vertex use dijkstra again to find the shortest path back to the original source.
I tried, but it seems to fail and I cannot find the reason.
Google the travelling salesperson problem,that finds the shortest cycle starting from the source covering all the vertices.The code for travelling salesperson is also not difficult to implement.
Since any vertex can be visited more that once you are basically looking for the shortest closed walk in a graph. The problem with your approach is that dikstra will only find the shortest path from the chosen node back to the source . This will produce a star type solution, where you have multiple paths coming out of the source vertex. Which could be longer then a walk.
This is an NP problem, as Vincent stated, but you could try implementing it using a random walk algorithm. Or look at the Traveling Salesman Walk Problem (http://dspace.mit.edu/handle/1721.1/33668)

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