My graph contains no such edges which connect a vertex to itself. There is only one edge between two vertices. From Wikipedia i got to know about some algorithm which are used for calculating shortest path based on the given conditions. One of the most famous algorithm is Dijkstra's algorithm
, which finds a shortest paths from source vertex to all other vertices in the graph.
But by using Dijkstra's algorithm
, i am unnecessary exploring all the vertices, however my goal is just to find shortest path from single source to single destination. Which strategy should i use here? So that i need not to explore all other vertices.
One of my approach is to use bidirectional bfs
. By bidirectional bfs
i mean to apply two bfs
one from source node
, another one from destination node
. As soon as for the first time when i find any same child
in both tree,i can stop both bfs
.Now the path from source to that child union
path from child to destination would be my shortest path from source to destination.
But out of all the approaches described by Wikipedia and bidirectional bfs
, which one suits best for my graph?