 Hello, I am Vinit Thribhuan from the Computer Science and Engineering Department, Vulture Institute of Technology, Solapur and today we shall see how to derive minimum spanning trees from graph using Prim's algorithm. So these are the learning outcomes for today's video lecture at the end of this session. You will be able to demonstrate the familiarity with Prim's algorithm. You will understand how Prim's algorithm works to find out minimum spanning tree and you will also be able to apply Prim's algorithm to find a minimum spanning tree for a given graph. So these are the contents for today's video lecture. Now we shall see what are graphs. A graph G is a pair of set V and E where set V is a finite set of vertices also called as nodes and E set is a finite set of edges connecting two vertices. An edge E belongs to set E is a pair of two nodes U and V where U and V both belong to set V. A graph which has weights assigned to the edges as we can see in the diagram given below are called as weighted graphs. So this is a figure of a weighted graph where the edges are having weights. So what is a spanning tree? A spanning tree of an undirected graph that is a graph having no directed arrows is a sub graph of graph G that spans or covers all the vertices of G. Now, as you can see in the leftmost diagram, we have an undirected graph having four nodes. So according to the definition, a minimum spanning tree is a connection of all the vertices where all the vertices are covered. So in the three diagrams, we can see in the first MST, we can see that all the all the nodes have been covered with three edges. Similarly, in the second tree, we can see that all the nodes have been covered and this tree also has three edges and similarly with the third spanning tree. So based on our definition of spanning tree, what are minimum spanning trees? So a minimum spanning tree for a weighted undirected graph is a spanning tree with minimum weight. As we saw in the last slide, a graph may have many spanning trees, but but the least weighted or the spanning tree having the least weight is called as the minimum spanning tree. So as we can see in the left diagram, there is a weighted graph given. And at the right, we have a spanning tree, which is minimum in cost. So as we can see that HBE is having weight three, AD is having weight one, AB2 and CD having weight two, which makes it the minimum spanning tree. The minimum spanning tree T of a subset of graph G is a subset of graph G, such that it forms a cyclic subset. As we can see, no cycle of edges should be formed in the minimum site spanning tree. It connects all the vertices. That means all the vertices should be included. And the total summation of the weights should be minimum. So we call the problem of determining the tree T from the graph G as the minimum spanning tree problem. So what is the minimum spanning tree of the given graph? Pause the video and answer the question. So if you have correctly attempted the question, the question was what is the minimum spanning tree of the given graph? Now as you can see, the graph has equal weighted edges. That is all the edges of the given graph are equal in weight. If this is the case, then your graph may have multiple minimum spanning trees having the same weight. So we define a very important property of minimum spanning trees here. That is, if a graph is having equal weighted edges, so we may have multiple minimum spanning trees, but the weight of all the spanning trees will be equal. So this is the prince algorithm to find the minimum spanning tree. First step is assign a key value to all the vertices of the graph and initialize it to infinity. And to the starting vertex, we assign a key value of zero. Start from any arbitrary node. We may call it as the source node. While set A, which maintains the visited, visited set of nodes, we pick a vertex you not present, not present in visited set A with the minimum key value, we include the vertex you, which we have recently picked and added to the visited set and we mark it as visited. And we update the key value of the adjacent vertices of you. So how does the updation of weight takes place? If weight of an edge UV, that is node U2V is less than the previous key value of V, we update the key value to the minimum of the two. This is the algorithm. We, as we see that lines number, line number one to five takes O of V time for execution. This particular line takes O of V into log V time, that is O of V log V time. The block from eight to 11 lines of code takes O of E into log V time, which gives us a total runtime complexity of O of E log V. Now we shall see an example of Prim's algorithm on a weighted graph. Now, this is the example having nodes from starting from A to I, all the edges have been weighted and we start our computation or determining the minimum spanning tree from node A. So as we can see the key value for node A is zero while the key value for all the rest of the nodes is infinity and in the visited set, that is set A, we set A is equal to one and the rest are unvisited. That is why we have denoted it as zero. So here we set A as one that is visited. And we have updated the key values of B and H since B and H are adjacent to A having the weights four and eight. So now we include node B in the visited node and also in the MST. We update the visited node for B, that is we make it one and now all the nodes that are adjacent to B, that is C has been updated with the key value of eight. So the updated key value of eight here is available. Now we have to select the lowest key value term or the node amongst C and H. Since C and H are both eight, we can choose any of the two. We select C. Now the key values of the adjacent nodes to C have been updated. As we see that I and D node are adjacent to C. Therefore I and D, the key values of I and D have been updated. Now as we can see that the minimum key value available was two. That is why I has now been added into the MST. Now the rest of the adjacent vertices of I, which are still unvisited are added into or their key value has been updated. So we can see that the key value of G has been updated here with six. The key value of H has been updated here with seven. So moving ahead now as we see here that the node with the least key value which is unvisited is selected and we select node F. So node F has been selected and the adjacent nodes of F that is G, E and D update their key values. So we can see that the value that is the key value of G has been updated to two. The key value of E has been updated to ten and the key value of D has been updated to yes. Because the updation it is at weight seven from C and it is at weight fourteen from F. So we keep it at minimum as seven. So the next least term or least key value was G. That is why we select G as the next node to enter into the MST. We mark it as selected or visited and then we go to the adjacent nodes of G. Now as we see here that H is at a distance of one from G that is why we update H key value here. Next is H. So we visit H here and the adjacent values of the nodes of adjacent nodes of H are updated in their key values. So we see here that the next least key value was D for the node D. That is why we select node D here as our next node and mark it as visited. So we see that after every node has been visited we mark it as visited here and search for the least key value only for those nodes which are not yet visited. So ultimately there is only one node remaining which is E which is at a distance of nine from D and we select it at the end. So we see that all the nodes have been visited here. It has been marked with one. The MST contains the set of all the nodes and the entire tree has been visited with the minimum weight. So if we compute the weight of the entire minimum spanning tree we see that the sum is 37 where the shaded edges are representing the MST. Now these are the references referred to for this video lecture. Thank you.