How to find all equals paths in degenerate tree from specific start vertex?

How do I find the shortest path from every vertex vvv to vertex sss, where v,s∈Vv,s∈Vv,s \in V?

  • Let G(V,E)G(V,E)G(V,E) be a directed graph with positive weights on its edges, and let s∈Vs∈Vs \in V be a node. Suggest an algorithm that in time O((|V|+|E|)log|V|)O((|V|+|E|)log⁡|V|)O((|V| + |E|) \log |V|) time algorithm that finds, for every vertex vvv, what is the length of the shortest path vvv to sss?

  • Answer:

    Run http://en.wikipedia.org/wiki/Dijkstra's_algorithm in the reverse graph of GGG, where sss is the source. The edges of the shortest path from sss to a node v(v∈V)v(v∈V)v ( v \in V ) in the reverse graph, will form a shortest path from vvv to sss in the original graph.

Bidhan Roy at Quora Visit the source

Was this solution helpful to you?

Other answers

First reverse the direction of all edges, then use dijkstra algorithm. Dijkstra algorithm computes shortest path from 1 vertex to all other vertexes in the graph in O((|V| + |E|) \log |V| ) . You can then back trace all of those paths to return the answer.

Chan Le

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.