Dijkstra's Algorithm
Dijkstra's algorithm is used to calculate the shortest path between the one node (our choice) and every other node in the graph. Let's start the algorithm part- We have a graph as shown in fig (1.a) Firstly we have to select one node for example we select node C as our source node. In the algorithm we will mark every node with its minimum distance to node C.For node C,this distance is 0.For the rest of nodes this distance will be infinity.(Fig 1.b). Secondly we are having a current node as C. Now, we check the neighbours of our current node i.e A,B,D in any order. Suppose we begin with B. We add the minimum distance of the current node in this case it is 0 with the weight of the edge which connects C(current node) and we obtain 0+7=7. We compare distance with the minimum distance of B(infinity) and we find that the minimum b/w infinity and 7 is 7.therefore 7 remains as the minimum distance of B. (Fig 1.c) Now,let's check neighbour A. We add minimum distance