You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Dijkstra’s algorithm: Dijkstra’s is shortest path algorithm, whichfollows greedy based approach to determine the shortest path from asingle source weight graph ((G)), where the weight of each edge from(u) to (v) is non-negative i.e. (w(u,v) \geq 0). Initially, sourcevertex is assigned a cost of 0 and all other vertex assigned with(\infty) cost. To find the shortest path, Dijkstra’s picks theunvisited vertex with the lowest cost, then calculated the cost fromsource to each unvisited neighbour vertex. Time complexity forDijkstra’s Algorithm is (O(n^2))
Bidirectional Dijkstra algorithm: 1. Alternate between forward traversal from (source) node andbackward traversal from (target) node 2. Calculate (d_f(v)) distance for forward traversal 3. Calculate (d_b(v)) distance for backward traversal 4. Stop when (Q_f) and (Q_b) queues are empty 5. After traversal end, find node (u) with min value of(d_f(u) + d_b(u)) 6. Find shortest path from (source) to (u) andfrom (u) to (target), combine both paths to get final shortest pathin a graph
Running time for finding shortest path between two points can beimproved by implemented bidirectional search along with Dijkstraalgorithm i.e. executing Dijkstra algorithm from both directions (fromsource node to target node and vice versa) simultaneously. For ahomogeneous graph Bidirectional Dijkstra approach has runtime of(O(2*(n/2)^2)), i.e. 2 times faster.
Consider that we have to find the shortest path between Dublin and Corkcity, then Bidirectional Dijkstra algorithm will start exploring pathsfrom both cities at same time and algorithm will stop traversing whenboth paths meet i.e. when a node is scanned from both directions.However, if Dijkstra has been used here then it will take more time tofind the shortest path, as algorithm will start traversing from a sourcenode (i.e. Dublin city) and stop when it reaches target node (i.e. Corkcity)
Iteration
Nodes
Edges
Source
Target
Dijkstra run-time (in milliseconds)
Bi-Directional Dijkstra run-time (in milliseconds)}
1
4
3
0
3
0.034383466
0.025146117
2
5
8
0
3
0.059016397
0.047726304
3
6
10
0
3
0.062095513
0.05593728
4
8
10
0
3
0.064148257
0.051318606
5
9
12
0
3
0.087754816
0.077491095
6
15
15
0
3
0.08980756
0.072359234
7
18
14
0
3
0.126756957
0.088781188
8
32
28
0
3
0.167811841
0.134967934
9
50
35
0
3
0.185773353
0.140099794
10
60
35
0
3
0.119572352
0.095452607
About
Python implementation of Dijkstra and Bi-Directional Dijkstra using heap and priority queues in python