# DAA 22 Nov

- **Course:** 5101 - Design & Analysis of Algo
- **Recorded:** 2026-11-22 00:00
- **Transcript:** 730 segments, 12244 words
- **Made by:** deepdml/faster-whisper-large-v3-turbo-ct2

---
Okay, so the last lecture we have started discussion on the directed graph. Okay, and we have already understand number of terminologies that are being associated with graph like edges, vertices, in degree, out degree, source, sink, path, number of terms we have learned. So, these terms will one or more way will come definitely while discussing then we discuss about how the graphs can be represented in the memory. So, there are two mechanisms, one was adjacency matrix, so that is a vertex to vertex matrix we will make and in that we will try to fill out value 1 if there is a direct vertices between two pair of vertices otherwise we will assign a 0 value. So, the resultant will be an adjacency matrix. So, this is also called as the sequential representation. So, then the next representation was the link representation and that is you can say will be treated as the representation using link list representation using link list.

So, that is also referred as link representation using link list where we will try to make the list of all the vertices and how many vertices are being connected to each vertex are made in form of a list. So, let us say there are three vertices. So, we will have first three vertex set and each will have the number of vertices they are corrected with. One important thing in the last lecture that was asked. So, there may be link between 0 and 2 or may not be linked between 0 and 2, but there will be placed one after another. At last, there will be a null load as as in case of linked list a null was inserted so that that indicate the end of the list so there are the two representations so we have seen adjacency matrix and adjacency list adjacency matrix and adjacency list so in adjacency matrix you can see it is also sequential representation you can see and this is you can say link representation This is useful when your matrix is dense. Dense means that the graphs are highly

interconnected and this is used when the matrix is sparse. So when there is a sparsity, high level of sparsity, then we will prefer a link representation over the adjacency matrix representation. But preferable is this one. So while representing the graph in the memory, we will prefer adjacency matrix in place of adjacency list then we have started and stopped at this point there are several operations in the graph as like as all the data structure that we have seen so far so first one is searching in graph insertion in graph deletion from graph traversal in graph okay but the most famous one is the traversal in the graph OK, so searching in the graph, you can see already we have seen in case of tree number of algorithms so that you can use any of them. And the basic idea is visit vertex by vertex and try to search. But insertion and deletion that is the case to case basis whenever we see in an algorithm.

So insertion and deletion will be done accordingly. most famous one in the graph is the traversal so depth first search and breadth first search i hope some of you have heard about and maybe most of you had also gone through this algorithm but i will just cover from very much scratch one one problem will be more than enough for understanding the idea behind these two algorithm that is depth first search and breadth first search okay so let us begin with traversing the graph so if you see the breadth first search uses important part is that uses a q data structure oh sorry just give me a moment breadth first search uses q data structure so we have seen q so it follows the first come first serve order and an auxiliary structure okay need to further processing and analogously the depth first search will use a stack this is very important in in your uh quiz or an object to a problem this will be used so bfs that is best for search primarily use q

and and depth first search will primarily use this tag so before going into the real uh algo part just i want to show you the basic idea it is very basic algorithm uh again i'm saying you most of you may be aware of these things okay so what is the basic idea of bfs and depth first search these are the two algorithms that are being used so first one is a best breadth first search so what it say uh if i draw in a form of a tree so it will move label by label then it will go in this side then again down then next label okay then again down then next level so what basically to indicate that if i choose this node then i will cover all its siblings then i will change the label then i will change the label okay but depth first search say go searching in the extreme of one direction then come back for other direction and so on so first it will go in this direction then it will come up then so what is basically showing it is not bothering about other siblings other siblings

or neighbors okay it is it is just going down down down down to the extreme then come up and this so these are the nodes where there may be some information that we are searching for okay so that is the basic logic traversal can be done breath for such breath means i will cover all the element in this, then I will go down, then I will cover all, then I will go down and in depth first search, I will keep on moving down, down, down till last, then come back, then again in next row till last, then come up then, so basically if you draw the structure, so this is BFS and for depth first search, this could be the structure. So these are the two basic ideas that we will see by algorithm how it will be processed. So if you talk about the BFS, so Q will be maintained to store all these values, label by label, label by label, label by label. So the Q will maintain, but here we will use a stack because we know that stack are primarily

used for delaying the operation, delaying the operation. If you want to delay certain operation and you want that some operation will be executed after something else, then we will put them into the stack. So although these informations will be available, these information, but they are put into the stack and we will use keep on moving this side. So the data structure that are being used in depth first search is stack and in case of depth first search it is Q. So let us see the algorithm one by one and try to understand the analogy. So these two things are clear. Now during execution of an algorithm, each node n of g will be one of the three states. There are different states in which a node could persist. So status 1 means ready state, they are ready, they can be visited. Second one will be the status 2. So either they are in the queue or stack, they will be treated as the status 2. third state will be the process state, means that we have already visited the

node and there is no need of revisiting again. We have visited, we have visited and no need of visiting again. So, that is the process state. So, whenever we encountered any process state, we will just pass or just hesitate to revisit or we will not visit that vertex again. That is the simple thing. Whenever we encounter a process state, we will pass. We will pass means that that is not needed to revisit again. So, let us start with the first algorithm that is breadth-first search. And these two algorithms are very common in also case of AI algorithm. when we will start the very basic ai or ai concept so you will find bfs dfs okay there are some other techniques depth limiting search and others are there so the base for all of them is these two algorithm bfs and dfs okay so here it is the general ideas begin at the start node a as follow we examine the start node so important part is that because the graph are

may be have multiple edges. So, we cannot directly identify a source. So, start vertex will always given. Start vertex will always given in the problem. Start vertex will always given in the problem. So, this, so there is a start node A, this is always given in the problem then we examine all the neighbors of a all the neighbors that are directly connected that are directly connected okay so then we examine all the neighbor of the a okay we need to keep track of the neighbor of a and we need to guarantee that no node is processed more than one that is that's why if someone is state 3 so they will not go to that node again state We will not go to that node again. And it is accomplished by using the Q to hold the neighbors that are waiting. That is important. So, 3 states, but the state 1 was ready state, state 2 was waiting state and state 3 was process state. So, if we encounter something in process state, we will skip because that is already with

visited one and waiting are those that are staying in the queue for BFS. So, this is the algorithm if you see very basic algorithm, initialize all the node to the ready state because if there is a node in the graph, it is ready to be traversed. So, we have initialized the node with a stator 1, then put the state, starting node A in the queue. Now, the process begins. So, first node, the start node is put into the pre-specified queue and change the state to the waiting state. Now, its status is changed as the status 2 because whenever item is inserted into the queue, so its status is changed from 1 to 2, that is waiting state. Now, what we have to do, we have to, here there will be a looping thing. Looping thing will be inserted and what we are saying in queue, if you can recognize in the queue, the queue, the order is FCFS. So, first will be processed first and then it will be nest. So, it is saying remove the first node from the queue, process n and change the status to the

processed. Then what I will do? So, a is process initial node, then add to the rear of the queue all the never of the n that are in the steady state 1 and change their status to 2. So, simply what I have did? I have started with a start node and then identify all the nevers. Nevers means that the siblings or the lay or those that are directly connected because this is graph. So, let us say 1, 2, 3, 4 are there. So, we will push all them into the queue and their status initially it was 1, now it is changes to 2. Initially the status was 1, now it changes to 2. So, let us see this example. So, here 5 is the start state. So, a different color is used. So, what I will do? Initialize all, so state of all the node is now 1. So, I have put pipe into the stack sorry q here it is the q pipe is added now what i will do i will pull it out and mark the color red that is called as the processed and all the numbers

of pipe if you see number of fibers we can reach one from five we can reach two from five any other node if you see there is no other possibility so these one and two will be pushed into the stack and their status will be changed to two that is waiting state now we can process one okay you can process two as well there is no any issue now i am doing what i have visited five its status is now three then i visited one so one neighbors are zero two and four So, what I will do? I will put them into the stack. So, that is 1, 2, 0, 4. So, 2 is already there. So, we are not adding into the cube. Then I will visit which node. Then I will process 2. So, 2 will be processed. There is no number of 2. So, we will go ahead. Then 0 will be processed. Number of 0 are 5, 7 and 3. Okay. So, we can choose ascending order or that is not an issue. So, I have put 3, 5 is already processed, so we are not adding 5, 3 and 7.

So, 3 and 7 is added and now we are processing 0. Then, then we will process other nodes and ultimately we will reach to the result. So, what I will do, I will start with this empty tree and show you how the process continue. Then you can refer the slide and all the states are clear. Just let me know. So, let us say we have this. So, first pipe was pushed into the queue, pipe was pushed into the queue and its status was changed to processed. Now we have pushed the element that is 1 and 2 into the queue. So, next node we are going to process is 1. One thing I am want to clarify here, you can process 2 as well, there is no problem. So, because since 1 is smaller than 2, that is why I am preferring it. So, when I want to process 1, so all it is never that is 0, 1 never is 0, 1 never is 4 and 1 never is 2. So, 2 is already there in the queue. So, you can put it in the queue because if you encounter a process node, it will be automatically omitted. But let us say we know

2 is there, so we are not adding it. So, 0 and 4 are added into the queue. Now, at their status, single line I am drawing, this is in status 2, this is status number 2, this is in state number 2, now we have picked the next node, so these two have done 2, there is no number of 2, so 2 will be directly processed, then we have shifted to the 0. So 0 has number of 7, 5, 3, so I have just added 3 and 7, because 5 is already processed. So, the single ring indicate its status is 2, the single ring indicate its status is 2 and now 0 is processed. Then the next node that is 4. So, never of 4 is what? 3 that is already there. So, we have processed 4. 4 processing is done. Then we go to the 3, 3 never is 2 and none or 2 are already processed. So, we will directly process 3. Then we will shift to the 7, 7 never is 6, so its status is changes to this single line and 7 will be processed, afterwards 6 will be processed and all the state will be now in state number

3. And this process will stop when all the vertex are colored in the status 3 or state 3, state 3 or status 3. So this is the simple process, we will start with the node and all its never into the Q And as the algo proceed, further numbers of the never of the never will be added and then we will get the resultant. The surprisingly if you see, after doing this, we will form a structure, so this is the order of traversal. When we will solve this problem with the DFS, you will find a change, order of traversal. And this is another example, here we are referring A as again the start node, A is again the start node. So, let us say A is a start node, I have put A into the Q, A into the Q and then process it, then the neighbours of A are B, B, E. So, B, B, E, the three neighbours of A that are pushed into the stack. A is already processed. Now we have shifted to the B. If you see B, the number of B are E and C. E is already there in the Q. So we have just put C here.

Now then after B, we will shift to the D. Now we are at the D. The number of D are A and G. So A is already there. So G we will add here. Then we will shift to E. E is here and e never are b a g already all our three are there in the queue we'll just process it that's complete now we will shift to the c c never is b and f so there is no x so f will be added here so i have traverses c as well okay now coming to the g so the number of g are h and d, d is already processed, so we have added h. Now we have shifted to the f, f is processed, there is no never of f, that is not there in the queue, f is processed, d is processed, f is processed, then we have shifted to the h. So now h is processed and it is never, i is pushed into the stack. So now i is processed and that is complete the side. So, this is how we can do the process. So, this is how BFS is processed. Now, that was the order that we have already done. So, this type of question may be asked. And this

is a BFS tree. BFS tree means that if you see the traverse, so you will find this like tree like structure is obtained okay and uh so um if anyone has any doubt let me know otherwise we'll see the next algorithm that is dfm sir sir i had a question sir yeah yeah sir i just wanted to know what is the selection criteria as a programmer or as an implementer when will i select bfs and when will i select dfs as the method of traversal yeah so um uh as a programmer um as i was saying that these are the basic techniques for the um uh this one uh ai search and searching phenomenon and let's say um some heuristically we are knowing that the the item that we are searching for is lying in the far depth okay of the tree so then we will prefer the depth first search and if we are seeing if we are having an and and some heuristics that the particular element of information is available on the uh this uh on the neighboring nodes then we will try to prefer the bfs and

secondly uh when we see the next uh after dfs we will see the minimum spanning tree so there we are targeting this bfs rather than dfs okay so and when we are going to solve some expression or something then we will prefer bfs so so that is a case to case basis not exactly we can say here we will go bfs or here we will go dfs so that is the if you have a heuristics that the information that we are searching is in very far away in the lower part of the tree so we will prefer dfs otherwise we will prefer bfs or we are solving some algebraic expressions so dfs are preferred so likewise the things are there so there is no specific criterion you will choose which one to go thank you sir there are no more questions sir we can move ahead okay so because this topic is more more familiar i hope most of the people on that's why i'm also going a little bit faster okay now the next algorithm that is depth first search the idea is searching the depth okay searching the

depth as we can go because so keep on searching the depth keep on searching the depth okay so So, the depth first search begin at a start node A and follow the criteria. So, as if you know, remember, the BFS was also starting with the start node. So, first we examine the start node A, that is fine. Now, if you see here, then we examine each node along a path P, which begin at A, that is we process a number of A and so on. So, that is very much important because here we are doing what? We are not identifying or searching the neighbor, we are searching the neighbor in the path downwards. If coming to a dead end, if we have finished all the element in the path, then our path we backtrack until we continue to the another path P-deaf. So, one path I have chosen, it got the dead end, then we will backtrack and then traverse another path. So, algorithm is very similar to the BFS. But now we will use stack instead of Q, that is very important.

And this is an open question to all, that is one problem or one objective will be definitely on this thing for the quiz 2. Now, so how the algorithm will, you can check, the algorithm executes a DFS on a graph G beginning at start node A, initialize all the node to the ready state, that is state 1, initialize all the node to the ready state that is state 1. Then push the starting node on to the stack. So, as if you remember, A was added to the queue in the BFS. Similarly, here we will use stack. Stack is this one. So, there are two operation in the stack that is push and pop, push and pop operation okay then those elements that are there in the queue will be treated as the waiting state they are in the waiting state okay now we have to again do a looping operation as similar as bfs okay so pop the top note n of the stack okay pop the top n of stack okay process and and changes status to the process state okay so we will just pop one element

and from the this one because we know that the structure is like this one so last come will be serve first so that is also called as the last in first out lipo that is stack it also called as last in first out okay so n will be process and changes status to the process state that is status 3. Now, push on to the stack, the number of n that are still in ready state, that is state 1. So, whenever we pop up any node like A or C, so all its nevers are pushed into the stack, all its nevers are pushed into the stack, that is important. So, clear thing in case of BFS, when we process a node, all its nevers are put into the queue. In case of DFS, when we process a node, all its nodes will be pushed into the stack. So, a stack order is different, that is lipo, last in first out and in case of q it is p4, that is first in first out. So, that is the, you can see, you can similarly what we were doing in the BFS is also coming in

the DFS. So, think, so we have started with the start node 5, we have pushed the 5 into the stack and change its status to the state 2 that is waiting. Now it is popped and marked visited. Mark visited means that now its status is 3. Then when we, whenever this process is done, then all the numbers of 5 will be pushed into the stack. So 5 is done and the number of 5 are 1, 2. So you can follow any order, 2 or 1 or 1 or 2. So, I am just following. So, here 5 was there, then 1 and 2 will be pushed into the stack. Now, we have come to the node 1 as per the, because 1 will be passed. So, we will come to the node 1 and process it, process it. The number of node 1 are whom, the number are 0, 4 and 2. 2 is already there in the stack. So, I just put 0 and 4. So, now after processing 1, I will shift to which 0 processing. Already 2 element are residing. So, I shifted 0 and never of 0 are 7, 3 and 5. So, 5 is already processed. So, I will just put 3 and

7 into the stack. The next element that will be processed is 3 now. So, here 3. So, 3 will be processed and never of 3 is 2. 2 is already there in a stack. After processing 3, we will go to the processing of 7 because there is no more element. So, if 7 is processed, its never is 6 and 1. So, 6 will come. 1 is already processed. Then we will process 6. 6 will be processed no never, then we will process 4 and then we will process 2. So, that is the order. So, first 5 will be processed, then 1 will be processed, then last 2 will be processed. So, 1 will be processed then, 0 will be processed then, 7 will be processed then, 6. So, that is the processing order. So, here the example proceed. So, this is how the processing is there. So, you see first I have processed 5, then 1, then 0, then 3, then 2, then 7, then 6, and then 4. So, the basic idea is whenever we encounter daily node, we will push all its. So, why the order is different? Because if you see multiple times 2 is appearing

into the stack. So, you can also choose that criterion also. If 2 is already there, you can uh add uh to another time as well as whatever the nodes are coming and if it status is already processed we will just skip it or the simplest way is that do not put into the stack if it is already there in the stack so any of the mechanism we will follow so order may be different depending upon the criterion you follow but the the the way what you are doing dfs will be same okay so i hope it is a little bit clear just so here we have started with five put all the never into the stack then uh next node will be pop up put all never into the stack next node will be pop up put all never in the stack and so on and this will come continue until we have visited all the vertex okay and in this example there is a little bit difference that multiple times same nodes are inserted into the stack so order will be likewise so if you see here 2 and 2 are there okay then 3

7 2 again is coming okay so the order will be like this one okay if you try to follow exactly what they there is present so put elements all times when they are appearing appearing in the stack okay so this also you can do in the q as well okay in the bfs as well so follow any more any of the strategy your solution will be more or like correct okay or if there are multiple options given so you can choose so never the options will be likewise confusing okay so now parambir if anyone has any issue let me know and then we will start the new part that is minimum spanning tree foundations so there are no raised hands so we can continue it okay okay thank you thank you so just uh taking a small break one person has anuja yeah please go ahead anuja uh the real life examples like in what kind of use cases we follow vfs and dfs as in general like when we prepare any algo or how we decide actually in the real examples if i just ask you so already

i have a tell bfs we will see from the next uh onwards so we will try to identify the just give okay so uh in case of uh dfs um sorry bread first search we will see in the minimum sparing tricky let's say we have to plan our journey to visit from different cities and to reach to a destination then in that case bfs will be more viable and let's say in because this tree and graph are very famous not of because they are a structural logical organization because they are helpful in solving the alphabetical problems okay where operands are on the intermediate node and of sorry operators are on the intermediate node and on the leaf there are operands okay so in that scenario this dfs are used and if you want to delay some calculation for example if you remember the association and precedence so where we delay the some operation because of the operators precedence and association then there the dfs are primarily used okay i hope you got the examples okay sir

hello yes sir actually i have a doubt regarding assignment 4 question in assignment 4 was incomplete actually in question was incomplete okay no so just mail me the screenshot actually what happened when i add the choices and add the answers now so i had privilege to update it in the last when your end semester everything is over then only i can update so what i will do i will just give you all people the benefit of doubt okay so just save me over an email or Parambhir or anyone can just send a single email I will correct it okay actually I have I don't have that question with me now it is regarding some pre-order post-order traversal okay okay okay I will recheck it if someone remember just anyone I am that is open to all anyone remember just share me on my email id I will correct it okay okay there are no more questions yeah yeah so now uh let us start an interesting example okay just give me a while it's coming with

in a minute okay so uh let us begin so uh let us discuss one interesting problem so uh earlier we have telephone lines that is wired basically where i come to our home and and our offices and then only we can connect to the other people via the telephone nowadays we are using wireless services but still the internet electricity line water pipeline everything still in the similar form it is directly come to us okay so now let us discuss a scenario there is a central office okay so this is a this problem that we are discussing primarily arises from those so this is in the city center okay city center okay and now the office has decided to provide telephone services to the multiple houses okay so that they can connect okay so now one nav approach is that all the house will have a single cable line from the central office okay single cable line from the central office but this will do what this will increase the

increase the cabling cost. And similarly, electricity line or water pipeline, everything, anything if you are targeting, so you will always reach to a solution that is increases the cost of cabling, piping, anything. So, that could be a NAB approach or very expensive. So, now people have started discussing, is there any mechanism to minimize or optimize the cost that are associating with the, that are associating with this phenomenon. So now they have start discussing about the minimum, minimizing the total length of the cable. So they have started discussing on wiring problem and what they have discussed, if we go like this one, the example that we are showing, that will minimize the total length required of the total length requirement is that it could be cable it could be uh ofc line it could be a pipeline okay and this this thing okay or this scenario is called as the concept of the spanning tree spanning thing and what could be the best possible solution so we have to identify

a term that is called as the minimum spanning there might be multiple spanning tree possible. Then we will choose what? We will choose the best or optimal that is minimum spanning tree because all these edges. So, let us say here length will be a factor, will cost. So, all these edges will have some weight, will have some weight associated with it. So, we will try to choose a spanning tree that is having the least weight on all the paths, least weight on all the path that is the minimum spanning tree. So, the now two things are important, all the nodes should be connected, first property all the nodes should be collected, all the nodes should be connected, okay. And second one is minimum cost, in minimum cost, okay. So that is the concept of the spanning tree. So, we will see in the next slide, just wait a while. that is minimum spanning tree. And in some of the literature, it is also called as the minimum cost

spanning tree. And in short, we will always say it MST, minimum cost spanning tree or minimum spanning tree. So suppose you have a connected and directed graph with a weight or a cost associated with each edge, weight or cost associated with each edge, the cost of spanning tree would be sum of cost of its ages the cost of spanning tree will be what sum of cost of its ages a minimum cost spanning trees are spanning tree that has lowest cost that is our target that is our aim to determine okay so this is a connected and undirected graph so you can use directed as well as undirected graph we will discuss on when the graph are directed then we have number of algorithm like Press, Bellman, Ford, Discastra. But when we are having their undirected graph, then we will use an algorithm that is called as the Kruskal. We will see how Kruskal process. So, if you have this thing, so you will identify a picture like this, if you see all the

vertex are covered, and the total weight of the tree is the at least as possible. That is the minimum cost spanning tree is there. You can have multiple spanning tree. Again, I am saying, you can have multiple spanning trees, but MST will be unique, not unique MST will be, will have the least cost. Now question is, someone says, if someone comes and say, I got another MST. So you say, okay, I agree because your cost and what I have estimated are similar. So, multiple MST are possible, but all the, all the MST will have the similar minimum cost or will have equal minimum cost. But in most of the cases you will find it is unique. So, but that is not always true. So, what is minimum spanning tree is a sub graph again, because it is not completely, it is a part of graph, undirected graph such that, these are the conditions, it is a tree. So, if you see, there is no loop or boundaries here you will found. So, minimum spanning tree from a graph is always a tree. So, it is a

tree, it cover all the vertex and number of edges will be V minus 1, mod V minus 1. So, let us say vertex are 10, so edges will be 9. And total cost associated with the tree is in the minimum among all the possible spanning tree. This is important, this is important. Now, now here we have a tree and here we are generating a minimum spanning tree. So, randomly there will be a number of steps is required and maybe we have reached to a situation that we are not getting a minimum spanning tree. So, there might be some specified algorithms and a specified process that we should adopt so that we will always get a minimum spanning tree in a least amount of time. So, let us say this MST. So, how to obtain, how to obtain a minimum spanning tree? So, there are number of algorithms and number of mechanisms that we will now discuss. So, there are three categories of problem. One is minimum spanning tree and this is basically

happen on undirected graph okay then there is single source key from a specified source node i want to get the sorted distance to the all the nodes that is called as the single source shortest path problem that is triple s pp plus pp the single source sorted path problem and let's say one asks if i want to obtain shortest path within any pair of source and destination any pair of source and destination so that is called as all pairs shortest path these two are directed graph and this is undirected graph and the algorithm that is very famous here is flied varsel flied varsel and here the algorithms are bellman ford and discussed and here that is cruz So prisms also come under the category of single source source path. So we will see one by one. So the minimum spanning tree that we will see follow a algorithmic paradigm that we have seen divide and conquer, we have seen brute force. Similarly, there is a greedy algorithm that is being followed by the minimum spanning

tree. Already we have seen these property, the spanning tree is just a sub graph that contain all the vertices and is a tree that is very important. So the graph may have multiple spanning tree we also we can also assign a weight to each edge with a number representing how unfavorable it is and use this to assign a weight to a spanning tree by computing the sum of weight of the edges. So basically what let us say the weights are assigned to the edges the weights are assigned to the edges. And in MST, in minimum spanning tree, the sum of weights, the sum of weight will be minimum, will be minimum, will be minimum. The sum of weight will be minimum. So minimum spanning tree is then a spanning tree with a weight less than or equal to the weight of other spanning tree so that is the concept so let us see an example if i ask the question is this graph a spanning tree so probably you will not say is a span tree because here we

are getting what here we are getting a close boundary okay and as i have stated that a mst or a spanning tree is a tree not a graph so there will be no closed loop loop, closed loop or boundary, closed boundary or loop. So, this is not a spanning tree. Next question if I ask, is this a spanning tree? Now your answer is yes, because there is dotted line indicate that they are disconnected. So, this is a spanning tree. So, spanning tree is basically a tree, it will never have a closed loop or closed boundaries. Now if you see the next example, if you see the next example, so here basically what we are having, we are having the tree, but they are disconnected, this is disconnected. So disconnected graph or disconnected tree will never have a spanning tree, the disconnected graph or a disconnected tree will never have a spanning tree. it must be all the vertices will be must be connected. So earlier example, it was connected.

Therefore, this is not a spanning tree. Now, if we talk about the minimum spanning tree, and if you can see in this example, the edge one has been left. And we have picked edge with weight 10. So it will never a spanning tree because it is on the higher side of the cost. Higher side of the cost okay so in minimum spanning tree there is one more thing that it will always hold will always hold the edge with minimum weight with minimum weight but chances of adding it is very small or sometimes you can say negligible as well. So, a minimum spanning tree will always hold the ages with the lower weights or smaller. Now, the first algorithm that we are going to witness for undirected graph and to obtain the minimum spanning tree, the first greedy algorithm is Kruskal's algorithm. So, how it works actually. So, let us say we had a graph and edges with their weights. So, what we will do, sort the, arrange all the edges in the graph in increasing order based upon

their weight. So, this is one thing that we have done. So, all the edges are arranged in the increasing order of their weight, increasing order of their weight. Then select edges. So, starting with the smallest edge, starting with the smallest edge, add edges to the MST. So, let us say I pick this one, then I will pick this one, then I will pick this one, but ensure that adding an edge do not follow any cycle. If I add any edge, so it should not create any cycle or closed boundary. Closed boundary is avoided because we know in case of minimum spanning tree, this should not be a closed boundary or closed loop. And this process will be repeated until we have covered all the vertices, we have covered all the vertices. And after, after doing all the step, we will obtain a minimum spanning tree. So, I hope the algorithm, the phenomenon is clear. The Kruskal algorithm will initially sort all the edges in order of their weights in increasing order and start picking 1, 1 edges as long as

no loop or closed boundary is formed. And this process will continue when all the process, when all the vertices are visited. Now, if you see the algorithm, it is little bit complicated. So, we started with a set that is values phi that is you can say empty set. And make set V is basically just assigning one one element in the set okay and this fine set will ensure there is no deduplication of the uh vertices or you can see if there is no duplication of the vertices so automatically the sub cycle will be avoided okay and there is a union operation one vertex will be added to the set a when we are ensuring that it is not forming any boundary okay so So these mix set, union and fine set I have highlighted because these are the critical operation and though the understanding the concept of Kruskal is very easy, but its implementation is a little bit challenging because you have to know these three functions, fine set, union

and mix set. So now, first step was sort the edges E into the non-decreasing order by the weight. For each edge, v, e in order of non-decreasing, wait, what we will do, we will keep on adding the vertices into the list or in the minimum span entry when they are not forming a closed loop or closed bond. So, for example, here we had a problem, okay, here we have a problem, so what I have did, this is your graph, this is your graph, okay, so what I have did, I have arranged the edges, in increasing order in increasing i have arranged the ages in the increasing order of their weights in increasing order of their weights okay now if you see here so hg is having the smallest weight that is of one hg is the smallest is that is of one then two and so on okay so this is first step so i have arranged all the ages in the increasing order of their weights now what i will do i will start picking the edges from the top and will stop whenever we found a closed wound so

let us start so i have visited first edge that is hg and let us start summing their weights one then i choose gf so gf is where here it is so its weight is two then a b a b is having the weight of 4 then i g i z is where i z is thick we are just taking this it's boundary so i have picked now if you to c d c d is having a weight of 7 provided 7 here then h i h i i can add its weight is 7 but it is not added because it is forming a closed boundary so this is eliminated okay then then AH is where here so it is marked and weight is H is coming fine so BC now we take B and C we take it its weight is 8 then DE if you see DE is here change it it is not forming a loop so that is 9 Now, if you choose EF, EF, if I choose EF, so a closed boundary is formed, so it is eliminated. So, this is D is chosen, EF is eliminated. BH, if you check, BH is again forming a closed boundary. And DF, DF, if you choose, again it is forming a closed boundary.

So, it is avoided. And if you see, we have visited A, B, T, I, Z, T, F, D, E. And some of the weights are 1 plus 2, 3, 4, 7, 14, 6, 20, 28, 36, 9, 45. So, overall weight of our MST is 45 and what we found that we have eliminated number of ages and mostly those ages that are higher in weight, that are higher in weight. So, we have eliminated those vertices and we are forming a tree-like structure. And if you see this arrangement, you will find that there is no closed loop or boundary. So, So, therefore, it is referred as the minimum spanning tree. Okay. Now, these are the steps that I have followed here. And ultimately, we have reached to the solution of 45. So, Parambir, you can add those who are having any doubt in this. I hope the problem is clear. The first, we are arranging the node in the ascending order of their weights and picking one by one such that no cycle is formed. Sir, Anuja has a doubt.

Go ahead, Anuja. Yeah. Sir, one question. this why ig is not a closed loop okay if you see ig and so uh here where loop is appearing this this i have avoided no actually if you see uh the ih sorry hi or ih however call it's closed right so you actually marked as a cross however ig isn't so that's why i'm questioning it's it's weight was six now initially it was peak and its weight was seven so if you see now lower weights are preferred over the highest rate because we have arranged the the edges in the descending uh ascending order of their weights okay okay so it's like uh the the previous to the next it has to be going a lower number and then so if the number is lower the chances is high that it will be selected okay okay thank you yeah yeah thank you thank you so i will solve one more problem okay you can see this this is another example okay so uh sorry sir there is one person subramaniam just raises his head yes please go ahead subramaniam mike is enabled uh sir uh this

is recording end semester exam paper so how many questions and uh multiple choice questions multiple select select questions and true or false types can be available question so this will there will be 50 questions and i guess your time will be two hours rather than one hours in assignment and other and mostly i will again add this multiple choice question match the call following and true and false so that type of problems i will ask so maybe possible you have to do something in the rough copy and anywhere and then you can attempt the choices but it will the structure will be like similar what we were expecting previously okay sir thanks a lot yeah just a minute so um i guess we can yeah it's one question based on what you just said now you're saying that we we will be required to do some kind of a minor calculation on a rough notebook and solve the answer yeah yeah i need to graph and all this so we'll have to solve something and

then find the answer now if it is getting proctored and our face is being captured it's quite sensitive to our head movement and uh anything that we look away no no so so the rough thing is allowed or in the start you can just show that this paper I will use for roughing, that is allowed. No problem, yes sir, that if we move our head, as has been told in our instructions also, if we look left right or there is too much of head movement or we look down away from the screen, we are likely to get locked out from the exam. So that is happening, really happening to you? Sir, we have tried, some of us have tried the mock test, but what is happening is that we are not very clear in the proctoring process uh whether the scb will do it or the moodle will log us out uh because no no so that is that is there but initially you can let's say i put paper in front of my laptop and start doing so there is no issue i'm just seeing

down and up down enough so that is allowed i guess that is i hope so because you know they are capturing image at every question change and if there is a variation uh and if you get blocked out then it is very difficult even to contact anybody in helpline and get the paper opened again because it's open only for 24 hour window and you can attempt so this will open for seven days i guess in the same exam the exam schedule is very clear sir fifth sixth uh the exams are starting from the fifth it is open for a 24 hour window like fifth is one exam so it opens 7 day for all the papers I guess, 7 day for all the papers. No sir, there is one day per paper and only on Sunday, weekends only. So we will be able to attempt it only once and to our window on one particular day only. So we can request you if you can seek some clarity and let us know that you know how strict is this proctoring proctor because in most of the exams we'll have to do some kind of a calculation on the paper

and yes because the algo required calculation okay and everything i cannot directly push into the paper yeah so if you look aside from the camera and look away i hope you don't get locked out because then it will be chaos and we do not know how to contact we will be i will contact the moodle team and ask what is the actual process and in the next class i will tell entire detail about this how the proctored things are being done and what are the consequences very kind of you thank you so much one more question uh do we have any previous year questions or sample questions so that we can also go through so uh all the assignments you people have done one two three four and quiz one and now after some time we will do quiz two so that will that is you can say the format of the answer okay sir okay sir thank you so because actually what happened like moodle is locked once the semester is end so i do not also had the access to the previous year questions

so how could i provide that yeah but it will be easy i guess you people are doing very well in that most of you are getting around nine or above it so that i guess there will be no issue one question from devasheesh please go ahead devasheesh mic is enabled hello yes earlier you have told that it will be after the quiz one or will it cover full syllabus uh okay so again i'm clarifying so i guess no no so i will not cover the very basic concepts of algorithm that we have seen so i will start with the time complexity till whatever i will cover i guess that will work or less than that you people need it or from divide and conquer i will start okay from divide and conquer not before divide and conquer i will ask anything no master theorem nothing from divide and conquer onwards okay sir from divide and conquer this will work okay but but you people are doing very exceptionally well in the exam so i don't think

you had any issue with the topic of syllabus okay but but i will try to put very less questions from the that uh time complexity or even no questions but mostly the syllabus will be from divide and conquer onwards okay okay parambir i guess you can circulate on others those who are not attending class today so the levels will be from divide and conquer onwards so it will be from merge sort onwards yes sir i put it in the group sir thank you so much uh one question uh it is now yeah so so one question has come from gerisha just one second uh gerisha i'm holding for holding for 15 seconds just wait yeah sir good morning sir sir yeah it's a 15 minute break you can ask after that No, no, it was just 15 seconds, I was saying, now I am coming here, please. All right. Okay, sir. Say, good morning, sir. While doing the exam, so we write on a paper, do we need to scan and upload, is there anything like that, sir?

No, no, no, nothing is needed. I'm just saying because in graph, in everywhere, now you have to write something, then only you can attempt the choices, otherwise it will be wrong. For that, I am saying, yeah. So, all are multiple questions only. most likely from next time onwards for exam you have to come to our campus and and in the dedicated lab facility you have to give the exam for three or two or whatever the time is and then only you can leave so that element is probably in progress pcs has been installed some electric work and other things are happening so afterwards you have to come in the campus and give the exam and then only you will get the mark so that will be a highly proctored kind of things that is supposed to happen by next semester okay okay yeah i guess we are good to go yes sir yeah thank you yeah so let me solve another problem that is via the crystal algorithm as well so here we have a graph

so slightly so these are the ages one is five this is this is red one is the edges that has not been captured by the Kruskal for minimum spanning tree. So here we go. So this is the structure of the graph. I guess there is no edge in between. So again, I had to follow the same process that is V3, V4, because if you remember the edges, E is not represented, it is represented in the pair of vertices, that is V3, V6, V2, V5 and so on. And we are choosing one by one again. So, if you see here, so v3 v6 is first v3 v6. This is first selected because it is having the least weight of 1. Then the next age is selected that is v2 v5, v2 v5 is selected, then v3 v4 is selected v3 v4 v3 v4 is selected that is weight is 2 and if you come to v3 v2 v3 v2 v3 if you go so it is again forming a closed boundary okay not it is not forming a closed boundary it is selected okay and so on so if you see the process is similar and we are getting the weight of 18 for

this one so i just request everyone to attempt this question okay don't bother about the image that I have created, bother about the vertices that we have, the edges that we have arranged and keep on picking. So, when, when I, when my peg is complete, then we are finding what we are finding the edges, okay, that are there and that are arranged in sorted order, okay. Now, this is another problem, another question you people can think, okay, the weights are given and you have we will get this structure okay now let me solve some more quiz problem okay just for this da perspective or designing an analysis of algorithm this is very much important because you all people are mostly professionals or engaged somewhere so just a request let's say cover one class do some problems related to that class and close your notebook there is nothing needed when you appear in the exam you will recall all these things but if you try that one day i

will prepare for the exam then that will be very much difficult okay because there are some concept changing in in a lecture two three things we are seeing and if you don't follow this then it will be merge and and you will be confused a little bit now moving ahead so this is another example that you people can solve though i was targeting it in the class assignment but in view of time i'm just going ahead so you will get the result entries all already given now let us solve one problem so t is a spanning tree of connected graph g and v which of the following property must hold okay already we have covered number of properties so t contains exactly v minus one edges so if you remember t spanning tree is a tree itself not graph so the edges will be so this property will of course hold removing any edge from the tree make it disconnected of course because it is a tree and we know that in tree if you remove any edge if we remove any edge so it

will be automatically disconnected so this property will also hold and next property adding any edge t creates a cycle if we add any edge in the t so it will create a cycle it will create a cycle so this property will also hold so these are the property that is being there in a spanning tree and therefore the correct price will be d that is all of our correct okay now seeing the next question so in which order does kriskel algorithm select ages in the mst so let us see so in mst let's say one will be selected because it is least so these three are correct now after this two will be selected so two are there these three are correct then where is four four will be selected of course, yes, 3 is not selected because it is forming a loop. So, 4 will be selected. So, now this is wrong, this is wrong. Now, after this, 5 will be selected. Yes, 5 will be selected. Then 6 will be selected. So, the answer is no because it is forming a loop

because this edge, this edge, this edge has already been selected. So, 6 will not select. We will select what? We will select 8. So, choice number B is correct. Choice B is correct for the Kruskal algorithm because it is selecting the edges arranged in sending order and ascending order and we will choose those edges that are not forming a cycle, that are not forming a cycle. Okay. So, there is another variant that is, you can say, quotient perspective in likewise we have seen minimum spanning tree there is a another concept of maximum spanning tree or maximizing the sum okay that is not very famous in the literature but in question point of view that is also called okay so maximum spanning three okay maximum spanning three so minimum spanning three or maximum spanning tree so maximum spanning tree our target will be maximizing the sum of the maximizing the sum of the edge weights okay now next algorithm in this one is called as

the prims algorithm okay so one algorithm we have covered that is cruz skulls and next algorithm is prims and the next algorithm is the prims algorithm okay so prince algorithm is now you can say a little bit different mode of operation is followed here okay so what is the basic idea for prince algorithm okay just i will uh discuss the basic idea in the next class we will solve one or two problem and bellman for digestra and others algorithm we will see in the next class that are all part of the minimum spanning tree and we will try to also wind up the graph thing in the next class as well okay so three four concepts are remaining in uh my graphs that is uh prims uh cruskell sorry prims and dyke extra bellman ford plaid watson and advanced you closure of the graph okay and one more thing that because the syllabus of this dies you can say even two three semesters are less than less for this so whatever we will cover we the questions will be asked from that portion only okay so uh let us

understand the concept and and and then we will so the concept is in case of crystal what we were doing we were jumping here and there this age i have selected then some edge here i have selected then some edge here i have selected okay then some edge i have selected here so then combining all and we are getting a result afterwards okay so now now so we will here in print algorithm there will be a dedicated start vertex there will be a dedicated start vertex from which we will begin and let's say zero here if you say zero and seven okay so zero and seven one is 0.06. So, then I will choose a vertex that is having the least. Now, from these two vertex, from these two, I will try to identify the minimum. So, let us say I will exchange two, for example, then from these three vertex, I will try to identify the minimum. If I choose three, so from these four, I will try to identify the minimum and so on. So,

this process will continue and you will find a connected thing is created in each step rather than disconnected thing that we were witnessing in the case of cross-scull so in in case of prim algorithm we will see a connected thing so if you see if you see um this is an one good example you can prefer so let's say we are having same graph that we have seen so the source is a so i have started a then from here the minimum edge is b so now from b and a we will choose the smallest one okay so let's say a is preferred so i have chosen a h the next is smaller from h is one so next smallest this is eight seven six five chosen six okay then sorry and this is minus is two not six then six then next smallest is now in two six is ten fourteen seven eight eleven so so I will choose 8. Then 7, 14, 9 and 10. So 7 will be chosen. Then this will be chosen and we will stop here because we have covered all the vertices in the graph. We have covered

all the vertices in the graph. So basic idea of prints is select vertex 0 and grow the tree, repeat v minus 1 edges, add t in the minimum weight with exactly one end point in t. So, there should be one end point in the pre-existing tree. So, the structure that we will form will be a connected thing. So, now if you see here as another example, so you will get this thing. So, now if we see this example, if we see this example, so in which order prism algorithm select ages in the mst so let us say we have started with the source s so first i will choose which vertex so it will not be one because s has having two edges nine and eight so of course eight will be chosen so in c and d the choices lies now after this one so minimum one two three so i will choose two so two will be chosen so strike c will be correct So, same process will be repeated, no cycles will be formed and the selections will be based upon the least edges.

And one important thing is that there will be no disconnection, no disconnection. That is important. So, if a tree is formed, then new edge that will be connected with this tree. So that was said here also, if you see, weight with exactly one end point in tree, that is very much important in case of frames algorithm okay so this is uh prims algorithm so how it would actually works so that i will clarify this and then end this session so for each s we are initially setting its weight to infinity all the s are infinity and source is having the weight of zero then we are doing extract meaning extract mean means that identifying the minimum edge and adding to the u when it is not forming a cycle okay so in the next class we will discuss us some more examples of prisms and start the bellman ford and dice kestra and whatever we will cover so i guess probably three four classes are remaining with us okay that we will see where

we can go in and the syllabus will be that and entirely confining with that one thing okay so if anyone has any doubt so we'll take otherwise we'll close the session here Girishah go ahead, mic is enabled. Girishah, Anujay go ahead. Thanks for having me. So as you mentioned with this MST we can either have a critical either has a frame rate. So in what cases we will choose when? I mean what kind of... So in case of Pridna the source will be given and in case of critical there will be no information about source. We are just refining to the minimum weight ages. And does it also refinery says that the DAG, that is our directory cyclic graph, which actually refers to the same graph theory, is the same way we actually refers to those vertex and edges like we are doing with the MST? These are the concepts coming from the graph theory only, but there are certain algorithms assigned to it. That is happening.

okay i'm just trying to relate so that's yeah yeah that is relatable of course because it is actually coming from the draft theory only okay okay thank you so much satya go ahead please i hope i'm audible now sir hello sir i have two queries one is one is regarding the like you have mentioned now from next summer onwards the exams will be at iat but now only so like will it be compulsory for everyone or because i am actually i'm just saying i don't know about the administration how it will go just say it some facilities are being in progress of development so that don't worry about that people will cater about those who are working professors and they may not travel to the location for one week that will be another challenge yeah yeah okay um one more doubt i have so sir like uh uh will the questions will be similar like quizzes and all like uh can we expect yes yes very similar exactly similar okay but same different question but will be the pattern

will be seen okay okay okay sir thank you mohammed go ahead please just a quick question uh are we going to have quiz two also because that was mentioned mentioned in the syllabus yeah yeah qs2 i guess after we have given a time frame of 25 to complete the quiz question addition and afterward you will get it so that is part of our curriculum as well okay so because you people are not here so assignments are done then two quizzes are there and they have some weighted and then then ensam and mid-science are there okay and the syllabus will be from uh primary search uh from uh divide and conquer onwards still whatever i will cover on the last class okay so that will be the syllabus for quiz two for end semester no that will be the syllabus of end semester and quiz two syllabus will be whatever i will talk to till today because i hadn't had the questions so i will add so till today's class i will add okay okay thank you sir jen go ahead please yes sir good morning

actually i missed one assignment because i was sick for a week or so and do we get any extra assignment to cover for that no no so there is no such provision so far i know but i don't know about the moodle support if they support you then they can edit but don't worry it is not covering i can it could be around four five percent in your entire percentage mark so that will not end problem for you also so so the the total assignments and quiz cover what percent uh so again that that that thing is not very much clear because it is dynamically but it is uh you can say benefit to the all the students that who have attempted but there is a fixed pattern but i don't recognize that right now but there is some some so most of the waiters rely on your mid-sem and end-sem exam and quizzes assignments are having a very least wait the quizzes have the okay both quizzes mid-sem and end-sem so these are having the

significant portion of your marks others are very lower okay got it thank you hello sir yes sir it does not affect any like marks over the in my exams like one assignment i also uh don't worry about the assignments you people are getting more than eight so that is more than enough Okay, I don't know that. Okay, thank you, thank you. Odai, go ahead, please. Good morning, sir. Sir, my question was, this is the assignment, we can attempt to see it, but we can see it. I can't see it. Okay. Sir, the question was, the download, the video recording, the classes, I can download it, I can download it, but I don't know if it's a chance to download it, or if it's a provision, I don't know if it's a provision, I don't know if it's a provision. There are no more questions, sir. Yeah, yeah, thank you, Parambir, for supporting me today. Thank you, Parambir.

