 and today we shall see the working of Dijkstra's algorithm to find a short path from the source node to all the other nodes in a given graph. At the end of this session, all of you will be able to, you will come to know Dijkstra's algorithm and you will also be able to apply this algorithm to find a shortest path from the source node to all other nodes or the destination node in a graph. These are the contents of today's video lecture. So Dijkstra's algorithm is applied to us to find a single source shortest path in midst of all the nodes of a given weighted graph. Say for example, this is a weighted graph with edges having positive weights. So given a weighted directed graph such that each edge has a positive weight, the objective is to find a shortest path from the source node to the destination node or to all other nodes which exist in the graph. Say for example, my source node is node A and my node of destination that is destination node is E. So from A to E, how many possible paths are available? So if we see here, one of the paths available from A to E is A to D and from D to C and from C to E which gives us the weight of 19, a collective weight of 19. A to C is again one path, one edge and C to E is the edge where the addition of the edges is 5 plus 4 that the path weighs 9. A to D, here A to D, D to B, B to and B to E, so this particular path weighs 20. So we come to know that the optimal path or the optimal route from all these 3 paths is A to C and C to E which weighs only 9 units. So this is the problem at hand that we have to find the shortest path from the source node to all other nodes or to the destination node. Moving ahead, these are the prerequisite. What is the relaxation function? So this function updates the weight of a given path. How does it update? Say for example, a particular node V, its distance is greater than the distance of a particular node U from the source plus the weight of an edge U to V. So if it is greater, what we do is we update the distance of node V from the source with the addition of distance U that is distance of node U from the source plus the weight of the edge UV. And I will explain it to you later on while we see the example and the parent of V becomes U that means the source from where the shortest path or the shortest route is coming to the coming to the node V is the source is U and extract min. This function deletes the vertex from the set and returns the pointer to the element from set Q which holds all the nodes in the graph. So this is Dijkstra's algorithm. I have referred to this algorithm. This algorithm is clearly available in CLRS textbook. The reference is available after the slides. So firstly, we initialize the single source shortest path algorithm having an having a graph G with V number of vertices. So set S initially is holding null values. At the end, set S will hold all the nodes from the graph. So when set S is full, we come to the termination of the algorithm. So we extract a single node which is closest from the source node, we extract it, we include it in the set S and for every vertex V which is adjacent to the recently included node U, we use the relaxation function as I had explained it earlier and we will see it later on. So the total running time of this particular algorithm is E log V. But sometimes also if the graph we are referring to is different in context and we might also get a bigger complexity of V square where V is the set of vertices. But basically if we come to the conclusion that the total running time, a better running time of the Dijkstra's algorithm is big O of E log V. For further clarification, you might refer to CLRS textbook for further clarification on the complexity of this algorithm. So this is an example that we will be looking to of the Dijkstra's algorithm. Here this is a weighted graph having edges, having positive weights and five nodes which are connected to one another. So initially the source node is A and we shall be determining the minimum weight or the minimum weighted path from the source node to all other nodes which is the objective of the Dijkstra's algorithm. So initially what we do is we consider that all other nodes are at infinity that means they are not connected or they are at infinity distance from the source node and source node is at zero distance from itself. So as B node B and node C are directly connected to node A that is the source node, so the distance of B is 10 and the distance of C is 3 from A which is being updated in our table and the rest of the nodes that is D and E are still infinity because we don't have a direct connecting path to it. So since out of these two edges 3 is a minimum edge, so we select 3 as the minimum path here and in this iteration initially A is been put in the S set and the next node to go in the set S will be C because C is at a minimum distance from A. So here we see that C has been included in set S as it is comparatively with 10 it is at a minimum distance. So at every iteration whichever node has been visited like we are going to update this particular table and whichever node the minimum weighted node from the source that is the minimum weight that the unvisited node is holding will be included in the set S. So now C has been included in set S and as we see that C has now been it has been made like it has been disabled. So now it is out of the race since it is already been included and C it is at a distance of 3 from source node A. So next we see at all the adjacent nodes which are adjacent from C now E is at a distance of 2 and E is at a distance of 2 from C and the node C is at a distance of 3. So it means that node E is at a distance of 3 plus 2 that is 5 from the source node. So we are going to update the weight of E from infinity to 5. Initially D was having the weight it was having the weight as infinity but since it has been now connected from C so the weight will be 3 plus 8 that is 11. Hope you all are understanding the updating of the weights and also B was at a distance of 10 directly but now we see that from C there is a edge having 4 weight so 3 plus 4 makes it 7 which is less and here the relaxation principle comes into picture and that is why we are relaxing or we are updating the weight from 10 to 7. So the minimum weighted weight here or the path here will be 5 and that is why the next node to enter in the set S will be 5. So will be excuse me will be E with having weight 5. So now we see A, C and E are in the set S and now we will check for the adjacent nodes of E. So we see that the adjacent nodes from E is D having weight 9. So the weight of E is 5 from A so 5 plus 9 is greater than 11 so we do not apply the principle of relaxation and keep it as it is. So 7 and 11 are the weights which are not updated in this iteration. So the next node to enter will be 7 because 7 comparatively 7 is less than 11. So node B having weight 7 will enter into set S next. So here we see that B has been included in set S and now we include B and check the nodes which are adjacent to B. So now we see that from B node C has been updated similarly we see that D is at also at a distance of 2. So 7 plus 2 makes it 9 because B is at a distance of 7. We saw it previously that B is at a distance of 7 from A since A to C is 3 and C to B is 4. So we conclude that a better or a shortest path from A to D will be A to C, C to B that is 7 plus 2 makes it 9. So the weight of D will be 9 and the last node to enter into the set S will be D. So here all the nodes have been included in set S and here as set S is full with 5 number of nodes which are the total nodes of the graph we terminate the algorithm. So what applications does this Dijkstra's algorithm have? This Dijkstra's algorithm is used for network routing where we have to find the shortest path for the packets to flow. It is also used in GPS application or GPS systems where a shortest path from source to destination is desired by the user. This is the reference that I refer to for this particular module CLRS textbook introduction to algorithms the third edition. Thank you very much.