Dijkstra's algorithm to find the shortest path between a and b. It picks the unvisited vertex with the lowest distance, calculates the distance through it to each unvisited neighbor, and updates the neighbor's distance if smaller.
Read More : https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
How to Use it : dijkstra(graph, 'A', 'B')