简体   繁体   中英

Dijkstra algorithm to find shortest path between two nodes in big graph?

Dijkstra Algorithm says

For a given source node in the graph, the algorithm finds the shortest path between that node and every other

I got the algorithm to find the shortest path between that node and every other. But my question if I need to find the shortest path b/w two specic node(say N1 and N2) for big graph like Linkedin/facebook do I need to calculate the distance between that node N1 and every other Node(user which means billion of users) on linkedin first, store it in cache memory and then return it from cache whenever shortest distance b/w two nodes is asked ?
Is dijkstra algorithm performs better there or any other algorithm like BFS better makes sense there ?

I came across similar question Java - Find shortest path between 2 points in a distance weighted map but this question refers the very small sample set and uses the dijkstra algorithm here.

I agree that Dijkstra Algorithm is not the best option for this kind of problem. Since you don't have weights, I don't see any reason why you should complicate the solution. A simple BFS would be perfect for you, and it would be optimal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM