# DAA 25 Oct

- **Course:** 5101 - Design & Analysis of Algo
- **Recorded:** 2026-10-25 00:00
- **Transcript:** 566 segments, 10361 words
- **Made by:** deepdml/faster-whisper-large-v3-turbo-ct2

---
Let us start. So, in the previous lecture, we were discussing about the avial tree, primarily discussing about the three types of rotations that we perform while doing the decision deletions. So, that were R0, R1, and R-1. And all these rotations depend upon the balance factor of the node B, balance factor of node B. And what is node B? So, node B is nothing but the node to the left of node A, which is the first node which is violating the balance factor property from the point of deletion, okay. So, the A node is the node that is the first node that is, just a moment, okay. So, these were the balance factor that we have discussed. So, the thing that we obtained that A is the first node that violates the balance factor property from the point of deletion and B is its left chain. So, accordingly we will take the decision whose balance factor is 0, 1 or B's balance factor is 0, 1 or minus 1 and accordingly we perform the rotation. Then one interesting

thing that we have also obtained that R0 and R1 were similar to LL rotation. Okay. And R minus 1 is similar to LR rotation. R minus 1 is similar to LR rotation. So, this means that if we understand the concept of insertion or primarily the LL and LR, then we can easily perform the deletion as well. Then if you talk in, you can say precisely, so if you know LL and RR rotation, these are the two basic rotation, then you can perform LR, RL, R0, R1 and R minus. So, these two rotations are very much important. So, simple also because single rotations they are, but they are very much important. Afterward, yesterday we have started the one of the interesting trees or we can say that the tree that are primarily used in the secondary storage, the M-way tree. So, why it is called M-way tree? Because there are ways, okay m ways of access if you remember in case of binary tree or binary search tree how many tiles or how many access path to the lower node were only two now when we talk about m way tree

so it here you are free to use any number of path from root to the lower then we understand different properties and checking up one structure of m way tree and and then we have concluded that the mv tree searching and traversal is easy just at each node we have to perform a binary search or linear search and today we will see the insertion and deletion how they are managed in mv tree. One important thing is that mv tree as I have shown that multiple BSTs were combining Why this is a thing? Because the same property that is left is less than right, left than root that is further less than right. So, this property will also held by the M-way tree. So, insertion and deletion we will see how they are impacting and afterwards in M-way tree we will further witness there will be an unbalancing issue and that will be resolved by the B-tree that is balance m-way tree. So in tree two, one or two more topics are remaining. Afterward,

we will jump to the graph, cover minimum spanning tree and other aspects and then we will see the dynamic programming. So we will try our level based whatever we can cover okay in our given time. Now this was one of the example that we were considering okay where we were trying to showcase the properties. So again, I am doing a repetition and then we will perform the insertion over it. So what property we have learned? We have learned the first property is all the nodes. So now a node is not having a single value. It can have an array of value. May have if m is 5, m child maximum child will be what 5 the child may be 2 to 5 and key will be 1 to 4 the key values that these are the key and if you see here if this is the node so its left is less than 18 and right will be greater than 18 but the constraint that it should be less than 44 then if you talk about 198. So the values here will be less than 198 but should be greater than 76 and here the

value should be greater than 198. So same property if you just talk about this single entity which is a BST. Okay but since we are combining so effect of these terms will also come. So there will be a range bound over the value that we are taking. Rather than taking just a smaller value we will have to take a value that is smaller than this, but should be greater than its left hand. So, at any point of time, if we see the key value ki, the value that are in the left will be less than the key and the value that are in rights will be greater than the key. That is a simple scenario of BST, but there is a restriction because the values that we stored here, let us say So, they must be greater than 18, but must be less than 44. That is the scenario. Second, first property was the child number of second property we have witnessed the value. So, Ki left will be less and right will be greater. Same BST property, but upon it there will be a capital.

The third property is that all these values should be always erring in a standing order and we will try to do the search operation or insertor operation in log of n time. That is important. That is why this mv tree is introduced. So I guess I have covered all the property. So let us say when we have to search for some value so what we will do we will first start with the root node so let's say i want to search for 350. so 18 say you can go to my right 44 say you can go to my right 76 say you can go to my right 198 say you can go to my right and since there are children on my right so let us explore that branch now it go to 262 262 says you can be on my right and there are some children on my right So, let us explore. So, 276, 286 and 350. So, we have achieved this. So, searching is similar. We will start from the root and we will first identify where could be the location of that particular element. If we are, let us say, searching for 77. So, 18 say you will be on my

right, 44 say you will be on my right, 76 say you will be on my right, 198 say since you are 77, So, you would be in my left. So, here is the possibility. So, we come down. So, 80 says you could be on my left and there are a link on the lower end. So, there will be 76 is here we obtained. So, any search operation will be start from the root itself. Second thing is that before performing any insertion or delusion, we have to do a searching. And we know that this BST does not allow the duplicate entities similarly m-way tree will also not allow any duplicate insertion so before inserting a new value we have to do a search because in deletion of course we know that to delete some number we have to first search is then only we can delete similarly insertion we have to search all possibility whether this is available or not if it is not available then only we can do the insertion and and at any node we can store m minus 1 here where m is the

order of the tree for 5 way m will be 5 and k the values that will be stored on the key maximum will be 4. So I hope you people now get the concept of m way tree. So you can see it is an extension or it is a multi-way variant of your binary search tree. So searching, this example, so searching of a key in a M-way search tree is similar to that of binary search tree, example 77 in the above tree. Now insertion if you talk about, so inserting a new element in the M-way search tree, we proceed in the same way as one would order to search for the element. To insert 6 in 5-way tree, we first search for 6. The tree node 7 comma 12. First child node so as null pointer. Since node has only 2 key, 5-way tree search can accommodate up to 4 key. So 146. So similarly, we will see the example. So let us do one by one. We will try to insert 6, 146 in the above discussed examples. Let me draw that example, then we

will see the resultant. The tree was 18, 44, 76, 198. So, those who can draw this tree with me, so in one go you will understand the insertion. So, the lower nodes are the leaf node. So, there will be null pointers. They are not pointing to any of the node. Now, if you go on the first part and if you remember the tree, so here it is address pointing to this node, this was empty, this was empty. Then there is another address pointing to this node and this is pointing to this one. Then here it was empty, it was empty and there is a pointer to this node. Then there is a pointer to 77. Again I am saying this tree is not the tree that we have drawn from the scratch. This is the tree that may be here after multiple insertion and deletion that we can, we have performed over it. So, this is an example tree. It does not mean that from scratch if you draw so you will find same kind of tree now what i have said insert six okay insert six so what

what is the procedure first we have to search whether six is already existing or not if we don't found then we will insert otherwise we will not insert and your option will be the duplicate element is present. Now, if you insert 6 here, so first 6 will come here searching. So, 18 says it could be on my left, then it go down, then 7 says it could be on my left, but and 12 say it could be on my left and one more thing that in the left there is no further entry. So this means that now we are very much sure that 6 is not exist in the tree. Then what we can do? We can insert 6 here because on any node this is a 5 way tree. So we can accommodate 4 keys. So 6 will be inserted here and a null pointer like this one will be created so 6 is just inserted okay now if this was a three-way thing okay so we cannot insert 6 so 6 will be inserted downwards so now let's say talk about the insertion of 146 insert 146 so it will first go to the root node root 18 says you will be left

76 sorry you will be on my right 44 say you will be on my right 76 say you will be on my right 198 say you will be on my left now there is a decision that it is greater than 76 and less than 96 so here we will go down so now on this note what we will do 80 say you will be on my right 92 say you will be on my right 141 say you will be on my right and on the right there is a pointer to the lower node so we will come down to here so 148 says you could be placed on my left and there is no further nodes downwards so you can be accommodated here but what is the thing here that is already having the maximum number of node so a new node on the left will be created whose value is how much 146 okay and the both the null pointer will be marked okay similarly if we want to insert let us say 251 so first it will go to the root okay then 18 say you will be on my right 44 say you will be on my right 76 say you will be on my right 198 say you will be on my

right so 251 and there is a pointer in the right word so you can go to now here so 262 say you could be placed on my left and there is no pointer in the left so let us let me accommodate you because i had a space so 251 will be added here across okay so insertion is simple just you have to check whether the element exists if not exist whether the node has available space if exist add it otherwise create a new node downwards. So, I will write search the key to be inserted. Second thing is that on the new page I will write what is the process first step is first step is search the key to be inserted as duplicate entries are not allowed okay so therefore we have to search if duplicate entries are allowed then nothing to search you can add okay but this will also help in maintaining the property of MV tree that is as similar as B tree on BST If we reach to a node where key could be inserted and have available space, then what we will

to add the node, add the key with null child pointer as per applicable. So, we can add two child null child pointer as like as the case of 146 or can add one child pointer null child pointer as in case of 6. Third one if the node is already having maximum key then make new node with one key and two null pointers. Okay. So, this is the simple process of doing the insertion. Okay. So, now in the previous example, we have seen the tree that was 5 way. Let me draw a 3 way tree. 3 is 3 way. So, 3 way means that maximum allowed child is 3 and maximum allowed key will be 2. Okay. let us make a three-way tree i'm randomly taking some example 4 7 8 3 2 11 17 16 44 43 21 okay so let us make the b tree so three way means that maximum key could be two so i have inserted four and 7 because maximum value could be there then comes 8 so it will be placed here then comes 3 so 3 could be accommodated on the top but it is already full so a node 3 will be

formed with 2 null right then 2 comes so 2 can be easily accommodated here because 2 keys are allowed then 11 comes so 11 can be accommodated here then 17 comes so 17 7 right 11 right a new node will be formed whose value is only 17 and this one then 16 16 could be easily accommodated here then 44 comes so a new node will be formed then 43 comes so 43 can be accommodated here then 21 comes so 21 17th right 43 left so here a new node will be formed that will value is 21 okay so now the resultant tree is 4 7 then we have 2 3 i am not drawing that pointers 8 and 11 then it will point to 16 and 17, then it will point to 43 and 44 and then this is pointing to 21. So, this is the resultant tree. Now, insert 1, 9, 22 and 26 in this tree. So, I fairly draw it in another piece maybe you people are confused then do this insertion okay just give me a moment so over seven two three eight eleven sixteen seventeen forty three forty four

and there is twenty one okay so i'm not drawing the lower note you know understand if there is three possibilities so here this is cross for this both are cross for 8 and 11 this one is cross this one is cross and this is attached similarly for this one one two third one is engaged these two are cross 44 and so there are three one two are crossed 21 then 2 are crossed. So, you have to insert what? 1, 9, 22, 26. 1, 9, 22 and 26. So, do insert everyone, then I will draw it. This is a 3 way tree, again remember this is not 5 way tree. 3 way means that maximum allowed child will be 3 and maximum allowed key will be 2. Then I will take the queries. Good job, someone has solved and uploaded. So, Rosh Anoshan has done, Janice has also done, good. So, let me insert it, then I will take the queries and then we will see the deletion in the mv tree. Why I am emphasizing more on this because b tree is just you can say a variant of it,

we will have some changes over it and then we can do the and perform the b tree that is important. now first of all i want to insert one so if first it will go to four four will say you can be accommodated on my left so it go here two and three so they will say i can accommodate you but i am still filled on one a node will be created and one will be inserted here then nine so four will say you will be on my right seven will say you will be on my right eight will say you will be on my right but 11 say you will be on my left but we are also you can be accommodated in a new node u form then 22 22 will uh 7 7 says you will be on my right 11 say you will be on my right 16 and 17 say you will be on my right 44 says you will be on my left so 22 will be accommodated here okay then 26 7 right 11 right 17 right 44 left 21 right 22 right but space is already full so 26 will be inserted here with the okay so i hope this is clear now let me take your queries

so one by one uh needed please provide the access to those who are raising query yes um i'm allowing you everyone so good morning sir audible sir yes sir while this example did clear my doubt to some extent but i request you to go back to the previous mway tree where you inserted uh 146 example the one If you can slowly explain how 146 resulted in creation of another child because when you say three-way, that means maximum child is three and maximum number of keys are two. So, in this case, how do we first start with identifying number of child and number of keys and then identify the limit that we have at each child and key? Okay. So, first of all, it will be given in your question. It is five-way. And if it is not given, so you have to identify any node in the tree with maximum child. So here the first node is having 5 child, this 48, 148 node is having 5 child. So this clearly indicate that this tree is a 5-way tree, getting one doubt clear I hope.

So either it will be given or you have to check the node that is having the maximum possible child and from there you can take a decision that this is 5-way or it will be explicitly given in the question these are the child pointers these are the child pointers and those are the keys so child will be always yeah yeah okay right thank you right anuja you can go next uh good morning good morning so so my question is uh when we uh asked for inserting six right so in this six uh we inserted six in the actual key uh where we we said that uh the null point that is uh available uh at the left right and and six is less than seven so we inserted within the key we didn't went to the leaves this is a scenario here now when we moved in the middle that is inserting 146 we actually have gone to the two sub trees that is 280, 92, 141 and then we said that yeah it is higher than that let's go in the right then we inserted it sorry then we checked out 146 is lesser than the values which

is sorry yeah lesser than the values which are available but again we see that null pointer is also available here in the left right but still we inserted all the leaf we didn't insert in the keys why why sir because here the the available key are four that is maximum because this is five way tree so child could be five key could be four so it is now already full so if it is already full so it will not accommodate but provide you the direction you can create a key and i will provide pointer access to it from the left words because you are less so it should be always taken from the left is it the case or is it just no no if let's say if let's say 177 was there okay we have to insert so it will be inserted here in the okay mid of the 172 and 186 so we can just update the null pointer also this is what we can see yes yes yes okay and in the second question this we just take an example right the three-way tree yeah here as we have one right the insertion of one

has to happen now within this one is actually the least number which i just see right four and then seven then two and three now did we start with the actual uh route itself where what this is the first point enough from here we can only get the access that is the thing from the root we can get the access to all the root so shall we start inserting one itself on the root is it what we can say but that question itself will become first we have to search now so well let's say i insert one here okay so what will happen there are the chances that in the lower part one may be present so first we have to show that the one is not present then we will identify its correct position where i should place it and one more thing this this let's say this four seven was not there only four was available okay and there was a pointer in both the direction and now i want to insert one so one comes here so one can be accommodated here but there are lower

pointer in the left side so there might be chance that one is located in the downwards so why i was inserting six if you remember here because there was no pointer in the downward direction to the left and here there is a pointer so there is a chance that one may be exist in the lower thing so we will first dig down to that then we will do the insertion okay so uh if i just make the understanding so clearly i've got a three-way trick question and the three-way tree does says this uh you can actually go max to max the three uh three possible search right that is yes yes available as three now if the three is found out okay in the third option sorry in the first route itself i say the null pointer seems available but it's still uh the lower sub tree is also available like here 23 is available so here one one blank is also sorry one uh both are the uh null pointers because there is no leaf actually right yeah so hence we took the uh left of this but i'm just

wondering sir 23 this is two comma three and three pointers are there oh okay three pointers because how you can restore uh 23 in the left of four right right that's where this got confused okay okay okay uh pishat and arayan you can go next uh hello am i audible yes please uh yes good morning sir so i have a doubt here in this three-way example so once we are inserting the uh node in nyan so it should be at the uh like we are taking from the center pointer right let's say like that determination like the left or right in binary was very straightforward like we know like which pointer we need to add it but in this case let's say if there are a lot of left pointers then which pointer like we like should choose like this node i have drawn and nine was inserted here okay okay okay so nine will be stored where to the right of eight but to the left of eleven so this is a common place so this is a common place it is greater than eight but

less than 11 oh okay so okay got it got it so in all the cases it will be like this if it's yeah then if it is a four ways some more nodes are there but the place will be determined because in bst we know lucky left is less than root and right will be greater than root so for eight this is left this is right but for 11 this is left and this is right because the pointers are merged to form this okay okay okay yes got it thank you oh jill can you go next yeah hello sir good morning good morning yeah sir i have a question like um sir in an aimway search tree increasing the order aim allows each node to store more keys and have the more children yeah does this always reduce the height of the tree and what is the trade-off does it you know get introduced in searching and insertion so uh of course it will reduce the height because on a each node we are accommodating more element but the thing is that while doing the searching

we have to do search for this things now 44 40 this was 47 something okay so what basically happening we are increasing the number of element on the each node that reduces the tree height but increases the searching time when the number of elements stored on each node is more so this is a trade-off okay okay okay sir or ek myra dousra question sir aapne 26 insert kiya na to jab hum a child pointer insert karengi to us me madab do child just 26 abne insert kya to 26 is a key to a key and two child do null pointers so that's the rule okay always because two ways maximum sorry minimum child should be two and maximum child should be m so minimum key should be one and maximum key should be m minus one okay so this is the rule of thumb every time this is the rule of thumb okay thank you sir yeah I'm good because can you go next because I'm allowed your mic uh because can you hear me hello sir can you hear me yes yes yes sir uh while answering one of the

questions which anujay has asked uh you mentioned that uh while inserting an element we we have always we always need to start with the root element yes yes but in in traversal we know that we we can start from left most as well as root and also from the right that is different case that is a traversal here we are primarily confined to the searching insertion and deletion so it will be start with the and and also if you remember the traversal thing now so we were first going to the root but not storing its value we were using a stack and we were then jumping to the left left left so at that point also we were starting from the root but we were not reading or fetching the value we are simply checking out the left left left left left left most portion and then we are doing so starting point in the tree will be always the root that's what in order traversal was what left root right this is the thing so first we will go to the root

and if we see the left child when then we will explore it so first insertion but we are not reading the value we are just exploring left left left and when we reach left then we will see the root and right so here we were using stack okay so to delay the operation so these entries are stored in the stack and we just traverse the leftmost part or traversal you can simply say that's printing the value so print function we will not call on the root we will directly call on the left channel okay okay so insertion ke liye hamay hamay shah shuru karna hai node se insertion searching everywhere trees root is why its name is root because it is the first um you can see a node you will encounter while performing any operation okay okay and traversal as well because it is left root right so when we reach to a node we will don't print or don't see the value store here we will just keep on checking the left left left

address pointer that is there fine okay thank you so i guess we are good to go uh there are three more uh hand raised hands okay yes yes sir can you go to the previous slide where the 146 insertion has happened yeah yes sir so basically in the level one actually it is a five-way tree so basically we can accommodate four keys so basically 146 can be accommodated in the level one only how why we need to go to the lift that is my question no so here the the keys available are four now that is maximum no sir in the level one sir not in level zero we can accommodate that one yeah yeah yeah so let me insert 146 okay so what will happen this these keys are greater than 146 yes so you have to shift the pointer right sir so that will be a complex Another thing is that since there is a pointer in the downward direction and if we do so there may be chance that these values we do not see may have 146. So to avoid the confusion and to avoid the pointer shifting and other respective rule

of thumb here or algorithm says explore extreme downward then insert. Okay so it is like the until and unless the exploration is over you can't insert. only we can insert because you know memory also does not allow any duplicate entry okay so so basically if that's the case then it would also like uh give us the skewness right yeah yeah so this problem will be solved by b tree so in that case 148 will pump up 146 will go down that we will see so that is another tree yeah so your doubt will be solved when we will cover b tree okay sir thank you sir yeah i mean actually can you go next i think my answer question was answered my question was if same value is coming for insertion as you said it will not allow duplicates yes yes okay thank you i think all of the questions hands raised was answered sir okay thank you thank you so before starting the deletion i will show you okay so deletion if I want to delete a key key so there are four possibilities okay so before

reading the right things just show you one thing okay so if I want to delete a key key there may be some node there may be some but I will only bother about these so either both are null or either this is there, this is null, this is null, this is there or both are both are there. These are the cases. Case 1, case 2, case 3, case 4. So, these are the cases. If we have null pointer, if both the pointers are null, simply remove it, simply remove. So, just taking a small break then we will join think about these these aspects okay so let us start i will take the queries after doing the deletions so there are three possibility when we four possibility when we perform want to go for a deletion so let me show with the example let's say i want to delete 77 no child easily remove it i want to delete 92 no child easily remove it and node will be shrink similarly if i want to delete 44 no child delete it shrink the node okay

272 286 350 everywhere 8 10 there is no child okay if this there is no child or you can say that both left hand so simply remove it so both left child and right child points to null in that case what we will do we will simply remove the key k then next case we'll see a separate example for each of these cases okay so don't worry now if we see the second case where there is left child one so if you see here let us check out the example let's say i want to remove 80 it is having one check and no right side so what we will do we will replace the 80 with 77 and that's done okay so 77 will come up remove 80 replace by 77 so there may be chance uh let's say i want to remove 80 so it is having only left check so we will pick out the highest element from here okay if one element nobody so we will pick out the highest highest element is what 12 so 12 will replace 80 okay so if it is right child let's say 262 we want to remove

so we will bring bring up the smallest element that is 272 so this means that while performing the case 2 case 3 or case 4 we may also lead to a cascade deletion key for deletion of 80 we need to delete 77 for deletion of 18 we have to remove 12 for deletion of 262 we have to remove 272 so in this case we will pull up pull up the largest element because we are doing the leftward okay here we will pull up the smallest element and if in the case number four we are we are having both the child so you can either choose either case 2 or case 3 simple situation okay so when both the child's are null simply remove it when having left child pick the highest element from the left hand when having right child pick the smallest element from right child if both are available you can go either case 2 or case 3 okay so this is the here it is written if ai and aj are null if ai not null and aj null if ai null aj not null if both are not null okay so here if you see

we have delete 262 and it is replaced by 272 so deletion of 262 deletion of 262 will also include the deletion of 272 so 272 is having both the point internal so 272 will be stored in a temporary storage and this will be removed then it will replace 262 similarly we want to delete 12 so see where 12 is so 12 is having left node but no right node so it will be replaced with the highest element from the lower one okay highest element is what 10 so 10 will be first remove if stored in temporary storage then it will replace 12. okay so 10 is here it is there and fine okay now i hope two cases are clear rightward and leftward okay and if you want to remove 77 remove it if you want to remove 148 remove it 151 removed so the nodes that are leaf node so removal of key is easy and will primarily emphasize on the case number one if if your node from where deletion to be happen is leave then we will be in case one okay so removing from the leaf will be very easy because we are in case one simply remove

it saying the node remove it sink the node now question arises if we want to remove node like 198 198 is having to both the child so either we can pull up 141 by removing it or pull up 262 so let's say if i want to pull up 141 then what we find it is in having the right child so from right child what i will pick 146 so here you can see there is a cascading so 198 removal required 141 removal and 141 removal required removal of 146 so 146 will be removed replace 141 in temporary storage we have 141 then it will replace 191 okay and if you see this will preserve also preserves the property of mv3 that is left is less than uh root root for which is further less than right okay so what i will do i will draw this tree okay already we have inserted something i will keep on deleting okay so let's say i want to remove let me draw something and then we will see the problem associated with mb3 that is being solved by b3 okay so here just give me that okay

so we were having 18 44 just give me a minute okay so here i will draw then i can simply remove it whatever i want so 18 44 76 198 then we have six seven well then we have 80 92 141 then we have 262 8 and 10 then we have 77 the last we have inserted then 148 151 172 186 we have 272 286 350 and there there's the last one that is 146 having both the pointers now okay now we draw the pointers this is pointing to 146 other are none this is not this is pointing to this node 272 28380 and other nodes in this are null okay similarly uh now for 18 there is a pointer to this node and this is having two null pointer followed by this and there is also a null then this is pointing to 77 then null then null and this is pointing to 148 this is 148 this is 148 then um this is pointing to this node this is pointing to this node and other two fields are now now we have this because why i have shifted to the pin so that we can easily remove it whatever we want now we

want to remove 272 okay i want to remove 272 so what i will do i will simply remove because this is having two null pointer and there is no further so 272 will be removed and its pointer will also remove so 272 is simply removed 272 is removed there is no change in the pointer this will become clear so there will be no change here we can simply remove 270 similarly if one want to remove 77 so what we can do this pointer will be null and 77 will be easily removed okay 77 will be easily removed and this pointer will be right now i want to remove 198 okay that is having both the child so either i can pull 141 or can pull 262 so that is totally up to you so let's say i want to pull one one remove 198 so removal of 198 required removal of 141 removal of 141 required because we are having the right child so it will pull the smallest element it will pull the smallest element and if you see here 148 is also having a left child that is 146

so this means that removing removing 198 required removing what 141 which required removing 148 which required removing 146 and this operation is thus called as the cascading this operation is thus called as the cascade delete cascade delete okay so removal of 198 will required 141 148 and 146 so we will start with this so 146 will be removed because it is having zero pointer case one no worries and it will replace whom it will replace this one 148 so here 146 will come and 148 will be stored in the temporary storage then then what will happen since uh we are removing 148 so uh you have to be uh just so if i remove 146 so it will add it to this node okay and then 148 will remove okay so what i can say here uh this this was the right pointer so we have to pick what smallest one so rather than 148 146 will be picked okay so it is not 148 it's 148 then it will replace with 146 so 146 will come up and will replace this one 141

so here we will have 146 okay i will tell why then this 141 uh now here 141 was there 146 was there so which one is highest 146 so 146 will go up i hope there is some confusion i will just remove it that 146 will come and the things will be sorted out okay now so there are some bugs so i guess i'm not going to do it so here if i want to remove 198 in this situation i'm just repeating so i have to remove either this one or this one that is totally up to so let's say i pick going in the right word direction dot what i encountered 141 that is already having a right child then we will go down and we want what 148 and 148 is already having one node 146 okay so how the things will happen 146 will be removed and it will try to come here 146 then what will happen this node will have overload overload means that maximum node so we will pull what we will pull the smallest one so smallest one is 146 so it will replace 141 will be 146 will come here now among this which

one is highest 146 so okay so i i hope there is some bug i am facing because uh what what will happen let's say 146 is inserted here no worries so how could be the node storing on its left will be lesser than uh will be greater than 146 that is the issue so uh i will uh i will uh check out this uh this issue and let you know in the next class okay i don't worry now uh if i replace this 192 198 with a right one okay think about that situation so we have 262 so that should come up and 262 will be replaced with first 272 and this 198 will replace with 262 that is easy part okay that is easy but when we go down here so 198 so we have to pick the highest one that is 141 okay and that is already having a right side so from right smallest one comes okay and then we have 146 so that also required a remove okay so in this this case uh this is removal from this path we'll see in the next class okay but removal from this path is easy to go okay

and uh okay so let me take your queries then we will start exploring the b tree and what are the problem with this uh m battery okay and this part deletion will will check surely check why it is not happening because uh why i am saying because if i want to remove 198 and going with the left words so left will pick the highest element but for removal of 148 141 required removal of 141 so because it is right child so this one okay okay uh just just give me a moment uh the doubt is now clear so uh in this example just remove it everything just keep patience for a while i will clarify it what is the problem okay actually the problem here is uh what we say that in this case just remember the deletion case okay so i just forgetting so if if a left is not null and a j is null then we have to pick what uh highest and if a right is not null then we have to replace with the from the sub sub tree pointed by aj delete k dash and replace with again in the subsequent calls

so here when we want to remove 198 with the help of left pointer so what we need we need highest element from the left side okay so that that was a problem so highest element from the left side is what 186 so 186 will replace whom 186 will replace 198 this is the uh concept okay so highest element from entire tree so that is 186 will replace 190 then there will be no problem and here is smallest element from all this so that is 262 is replacing 198 that that that was the issue that was arising okay now you can ask the question so in that the subsequent doubt will be clear uh yes uh please provide access to those who are basically yeah i have enabled uh you yeah thank you thank you sir good morning sir sir i am having a doubt regarding the insertion um in the slide number 10 if in the mv tree in slide number 10 when we are discussing sorry if if the key values yeah yes yeah in the slide number 10 if the key

values are in the last leaf node 8 and 11 instead of 8 and 11 if it is 8 and 15 then the next child will be in the left or right how we will decide that uh during uh if it is 15 so the child that lie in between 8 and 15 should be greater than 8 and less than 15. correct yeah so here 8 and 11 so 9 was inserted if it is 8 and 15 so 9 10 11 12 14 could be inserted so how how we say for example if 10 is there and 8 and 15 are there and if 10 has to be inserted 10 will be in the right of 8 or left of 11 left of so this point yeah left of 15 because this pointer is common so it will login go here only okay okay but pointer is common either left or right okay okay sir i i am i got it here yeah thank you sir yeah please so i just ask everyone to raise queries for the deletion so that your doubt will be clear oh can you go next uh good morning sir sir i have a question If you look at case 4 which was just discussed in the previous example now the complexity of the left oblique right when we have both the options are different. So if we are implementing it as an algorithm we will first see the complexity of left as well as the right and then select the least complicated route and do the deletion part. Am I right?

okay so yeah so but but the thing is that now how you know keep so determining the complexity will again again imposes another another complicated case while implementing now so we can either set that we will choose left one always or right one always so that you can do and yes obviously if you can modify the algorithm you can choose the number of nodes available on the left and number of nodes available on the right whichever is lowest we will i will prefer that path exactly because that was less amount of traversing will be required yes yes yes yes here in this case 186 is at the level two if that 186 was next to 146 or maybe even lower then we have completed this algorithm yes yes yes of course just moving to 62 and bringing it on the right yes yes yes yes needs to be done i think yeah that you have to do so you have to add one you can say special function that will keep on tracking the the complexity of both the path but that is not

there in the algorithm of deletion of mway tree so you can introduce that one so that could be a modification right thank you sir goodness you can go next good morning sir good morning second case case 2 and case 3 so then your case delete delete left side case 2 is this 18 removal is case 2 okay so 18 removal required the highest element to be picked from the left so which is the highest element that is 12 okay and removal of 12 required removal of each value 10 10 so 10 will replace 12 and 12 will replace 80 focus and third case third case so you can pick any other note so third case you can say i want to remove 141 it's right child so smallest element from the right child will be picked okay so the smallest from the right child is what 146 will be replaced 141 okay sir thank you i will shake uh i have allowed your mic all right good morning sir good morning uh sir if we want to remove uh 198 then we are saying

like we have two choices either on the right or the left like say if we go on on the left side then we are saying we will choose the highest so why is not we are choosing highest on the road itself are you from the like 198 is the road there so but there we are having two options like either we can choose right or left but on if we are going for either of the side then we are having two options like we are choosing the highest but why we are not choosing highest uh on the route itself like we can choose uh 272 uh no so uh if you choose uh here the logic may work but the thing is that the right side should have the higher value than 198. so from right side if you pick a smallest there will be no change in the pointer and from the right if we choose the from the left if we choose the highest so again there will be no change in the pointer so that is the logic from the left because we know that left is less than that of root and right is

greater than right of root so that that is the logic working here okay sir mohit i have allowed you morning sir yes sir what was the problem when you have explained earlier that 198 will be replaced by 141 148 and 146 i mean i didn't understand the issue so so let me explain so what i was doing so um for others who have joined so uh don't grab it because so what i will do for removal of 198 what i required removal of 141 agree for removal of 141 required removal of 148 and for removal of 148 we required 146 so 146 remove 146 comes here then 148 goes up and 141 goes up agree yes sir but 141 left child is 148 how this is possible not possible so there will be violation in the property that's why i was a little bit confused there um cascade delete i'm saying but we have to pick the highest from the left not the node that is fulfilling the if there was no note downwards okay if there was no note downward then that was okay case but there are

nodes in the downward so that is failing the situation so we have to pick from the entire tree the highest number that okay sir okay if i remember we were using in order successor in order successor if you remember in bst so in order predecessor or successor case will come here so in order predecessor of 198 will be whom it will be 186 just one value less than this value just less than and one and 198 successor will be 262 just greater than this so that property you can also adopt it so one more thing if i have to remove 141 in place of 198 then so uh so if you want to remove one 141 in place so what will happen we have right pointer okay and right pointer means that we have to bring back which element the smallest element so smallest it what 146 146 will replace 146 will come now let's say yes yes now the next next time now let's say i remove the 141 right and 146 came up now i have to remove when i did

146 came up okay yes this is 148 so now 198 again the just the smallest element is 186 okay so if you follow the same trend so 146 is replaced with 148 because we are picking from the right okay and 146 goes up then how could be possible that left of 146 is 151 172 and 186 getting the issue yes sir because this is the left pointer and left pointer should hold the value that is less than root okay and if we replace with 186 no problem but if we replace with any other value other than 186 then there will be a problem so our three property will boil it understanding why why we were yeah yeah yes uh shubha says i have allowed you a good mind sir so uh sir you are saying that whenever we are picking up uh from the bottom we need to select the highest value right like from the entire tree and from right side we have to pick the lowest okay another question uh like uh you are like deleting either the 18th or 198

like the node which are on the extreme left on the extreme right let's say if i have to delete something from the middle let's say i want to delete it uh delete uh 76 so is that be allowed yeah yeah that is allowed so here 76 is having only right pointer not left pointer so from right side we will pick the smallest and replace it 76 so from right side the smallest is 77 so that will replace this and and your work is done okay so it's not like we can only delete from like left or right we can delete from anywhere because we know not these three cases a i j a i and a j it could be null one could be null one could not be null and both could be not null so fourth case is little tricky and other cases are easy to go okay sir um there are few questions on the chat sir should we go with that yes please so amit has asked like uh is linear search being used in each node or binary search because if the number of element is less than

five or ten so you can use linear otherwise if the number of elements are higher so we will prefer binary search the main role is to reduce the complexity of searching on each node so that is depend upon the number of element available yeah okay i hope amit uh you got the answer if not you can you know drop the chat in the chat other questions are like um there are some screenshot if you go to the um the chat in this case yeah so 148 sir in this case it's right child so 186 goes up no no so in case of right child we pick a smallest one that is the case okay i think that's all i think the doubt is done yeah okay uh so chandan is having some doubt so let me take the query and end the session afterwards yes chandan and then we have allowed your mic i hope his queries hello yeah you can see yes yes please hello sir good morning sir yes um i i i had a query by but it got a resolve in previous question answer

so i one more thing yesterday night i was trying to submit our da quiz one but the thing is sir when i tried i started the attempt the iit partner site was just lagging it was not responding i tried so many times and after sometimes it got a time got up and submitted i think so i mailed them also haha so they will resolve they will take some time but they will resolve okay because i have not submitted all the questions answer there's few and then it got time got up okay no worries you can just mail the situation and and they will fix it but uh i guess today is the last day for submission yes today is the last day that is why you mail them yesterday night also you can also send some reminders as okay okay thank you okay we are good to cruise mohit is also having some yes mohit last but yes sorry again i'm having my same note let's say when we are sending sir 186 upper okay you have to listen so let's say we'll go step by step uh consider is that uh

in place of 141 where was the original one that said our original was written that 80 92 and 141 so if let's say we have i mean the 186 will go up here and then it will go up correct sir no no so because all the structures are true so what will happen just 148 186 will remove and just take the value of 198 done so no there will be not jumping from one step to steps okay but sir this is the right one right of 141 let's say 141 is the right child so here the value that will be replaced with will be the coming from the least value from this side if it was left then highest value will be automatically picked that i agree but since it is the right child and but uh from the top perspective you see it is the left child here from the left one the highest value from the left will be picked up correct sorry that that is that is clear that is very much clear yeah when you say 198 left and there you have we have to pick up the maximum

values yeah right sir yeah so one uh so directly let's say it will not go via 141 directly the 186 will go up and sit into the one in place of one night because because so there will be exchange of pointers what you are saying but there will be no replacement in the well i agree there will be exchange of pointers but there will be no replace in the key well so this is totally up to up to you how you implement the algorithm okay so you may say what key 186 will first go uh to replace 141 but uh 141 replacement will be now confined to this stream only now so it will always take take up the smallest one rather than taking the highest one i'm talking in the perspective of the larger perspective from upper words then i am picking 186. otherwise 141 will not replace with 186 it will replace with 146. in next class can you please give one more example in the same fashion yeah i will pick up some more tree and also before starting between i need some more

example to show you so uh of course of course i will come up with two three examples so that this doubt will be clarified yeah sure sure sure thank you so much thank you okay thank you all for joining thank you um i forgot the uh needed for yourself yeah yeah you're welcome sir

