Suppose we have a weighted directed graph G and we've found the shortest path between vertices u and v in G using A* search or any other shortest path algorithm. Now suppose that we double all of the edge weights in G. Does the shortest path change?
My argument is as follows: the shortest path does not change. Call the original path P and suppose that there exists a second, different path P' from u to v such that after doubling the weights of the edges, P' is shorter than P. Then,
weight(P') < weight(P)
after the doubling. However, dividing both sides by 2 we see that P' must have also been shorter before the doubling, so P was not the shortest path to begin with and we have a contradiction. Thus, P remains the shortest path after doubling the edge weights.
Could someone critique this solution? Is it correct?
Does the shortest path change when weights of all edges are multiplied by 10? If we multiply all edge weights by 10, the shortest path doesn't change. The reason is simple, weights of all paths from s to t get multiplied by same amount. The number of edges on a path doesn't matter.
Given a directed graph where every edge has weight as either 1 or 2, find the shortest path from a given source vertex 's' to a given destination vertex 't'. Expected time complexity is O(V+E). A Simple Solution is to use Dijkstra's shortest path algorithm, we can get a shortest path in O(E + VLogV) time.
And so, the only possible way for BFS (or DFS) to find the shortest path in a weighted graph is to search the entire graph and keep recording the minimum distance from source to the destination vertex.
BFS is applicable to unweighted graphs (or graphs where all edges have the same weight). For weighted graphs one can use algorithms such as Dijkstra's (which is a "modified BFS"), or A* (which is a "modified Dijkstra's") . However both Dijkstra's or A* do not work correctly with negative weights.
Yes, the shortest path remains the same. Applying a linear transformation to the edge weights does not change the shortest path, so long as you do not negate the edge weights.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With