[00:00:20] So, in the meanwhile, someone is agreeing for moderator. Let us begin the lecture and when the question and answer will start, we will add someone else. [00:00:27] So, in the last class, we were discussing about the balance tree or balance M-way tree that is also known as B-tree. [00:00:36] So, we have discussed about the properties like the root is allowed to have 2 to M-child and other internal loads except root are strict to have [00:00:52] ceiling of m by 2 to m number of child nodes. And obviously, if there is m child, then the key, [00:00:57] maximum key will be m minus 1. So, that is one property. And the next property that is quite [00:01:04] important for this B tree is the, all the leaves should be placed at same level. That is important. [00:01:14] And we have seen to maintain this property, the tree was growing upward. The tree was growing [00:01:29] upward in this direction, okay. So, these were the major property that we have witnessed. Then [00:01:37] we talk about that this is also called as 2 3 3 because 2 is the key and 3 is the number of child [00:01:44] we could have. So, a B tree of order 3 is also known as 2 3 3, okay. Then we started with an [00:01:50] example of a tree with order 5 and the basic indication of the order 5 may be given in the [00:01:57] quotient or you can see the maximum number of child in any of the node that will be the [00:02:02] indicative factor for the order of the tree. Then we discuss about searching, insertion [00:02:06] and deletion. Searching is as similar as M-way tree or you can say that as similar as BST [00:02:12] with an extension on the each node having some set of sorted key. Then we talk about [00:02:18] the insertion, different cases we have seen. Okay. And then we talk about deletion. Okay. [00:02:27] So, in deletion, this was the, you can say, structure. Deletion could be possible when we [00:02:36] have more than this much key, m by 2, on internal nodes. Okay. Or on leaf node. And if they have [00:02:46] just this one. If it is greater than this one, so we can simply remove the key from [00:02:57] the leaf. If it is just this one, then there are three cases we can borrow from the immediate [00:03:02] left sibling, borrow from the immediate right sibling or the last option was interesting [00:03:06] where we were performing the merge when both the, when all the siblings have just bare [00:03:14] minimum of m by 2 ceiling. So, we have seen a number of cases. Then there are two possibilities [00:03:23] of deletion, one was from the leaf node and another is maybe from the internal node, internal [00:03:33] node including root, including root. So, this is simple key, whether the element, it is [00:03:44] having maximum key or not, if it is, sorry, if it is having more than minimum key, fine, [00:03:49] we can simply eliminate it. And if it is not having minimum, then we can ask from the siblings, [00:03:54] either left sibling or right sibling. If both the siblings are not having the, [00:04:00] are on the minimum of m by 2, so we will merge with either left or right, bringing the root down [00:04:07] and forming a new node. So in this way, we have also witnessed that in cascade mode, [00:04:13] the tree height was reduced while performing the deletion. But at all point of time, [00:04:19] what we have witnessed that the leaf was maintained at the same level. And in this way, [00:04:26] maintaining the leaf and ensuring the m by 2 node on each child, B tree forms a balance variant of [00:04:44] of B plus 3, sorry, balance variable of M weight. [00:04:55] Now, then if we are removing the internal load, so we can either choose in order predecessor [00:05:02] or in order successor. [00:05:06] And same way merger will also be done, likewise we were performing the root if there is not, [00:05:12] it is not possible to pick out the in-order predecessor or successor from the tree. [00:05:18] So, we have seen number of cases in the last class and I hope you people have understand the idea. [00:05:23] And I have already shared this puberty. So, there are different cases explained, you can say [00:05:29] in a bookish manner. So, you can follow it. Otherwise, you can simply follow what the [00:05:35] steps are. So, let us do some two, three more examples and then we will jump to the, [00:05:45] I will also try to explain somewhat about this B plus tree. So, if you understand B tree, your [00:05:51] 90 percent concept of B plus tree is done. Properties are merely same, but there is one [00:05:58] distinction that I will tell. Now, here we have a B tree of order 5. So, I am just revising or [00:06:09] reviewing the revising B tree deletion. Now, we have this tree and of course, the order is 5 is [00:06:25] mentioned. If it is not mentioned, then we will see the node with have maximum child. So, if you [00:06:30] see here, it is having 1, 2, 3, 4, 5. Okay. Now, there is a requirement that we have to delete 95. [00:06:40] So, in case of B tree, what was the prerequisite that we should first search the key, [00:06:44] then only we can remove it. So, if you see here, it is 95. So, left of 110, [00:06:51] then we reach here. So, right of 86 and what we encounter that is 95. And here, if you go [00:07:00] m by 2, since it is 5, so we will get what 3 and here number of child is 1, 2, 3, 4. So, [00:07:06] it is more than maximum child. So, simply 95 can be eliminated. Then the next node is 226. [00:07:16] So, greater than 110 and here we encounter 226. [00:07:22] But if you see here, there are further charts. [00:07:29] Okay, if and it is having just minimum, this is having just minimum and lower child as [00:07:34] well. [00:07:34] So, what we will do, we will either replace with in-order predecessor or in-order successor. [00:07:39] But in case of predecessor, that is again having the bare minimum. [00:07:43] So, we will choose what, whom, the in-order predecessor. [00:07:45] So, 300 will be deleted and that is having the more than minimum key and will replace [00:07:51] 226. [00:07:52] So, the resultant tree with 300 here and 95 removed from here. [00:07:57] I hope this is clear. [00:07:59] So, if the node is having more than root, sorry, ceiling m by 2 nodes and if it is leave, [00:08:06] simply remove it. [00:08:07] If it is internal node, remove with its in order predecessor and in order successor, [00:08:12] they have more than minimum number of node, minimum number of keys or minimum number of [00:08:21] child. That is, of course, this is for minimum number of child. Now, we want to delete 221 [00:08:44] from this string. So, 221 deletion is required. Delete 221. Now, so, where is 221 greater [00:09:07] than 110, less than 300. So here we are encountering 221. Now the criteria is if the node is having [00:09:17] bare minimum that is m by 2. So they can ask from its left sibling or right sibling. If you see here [00:09:23] the left sibling is having just minimum but right sibling is having more than minimum. [00:09:30] So what it will do? It will from right sibling the smallest node will go to the root first [00:09:36] and from their root a node will come down that is 300. So, now 300 is here, 440 goes up. Okay, [00:09:42] so I will take the query and just complete this then, this page only. Then we want to delete [00:09:49] 220, 70 from the, this one, 70. So, where is 70? So, here, here it is 70. [00:09:59] Now, if you see the left sibling and right sibling, both are having where minimum. So, [00:10:05] what we will do, we will bring down the 65, merge with either left or right. So, I am merging with [00:10:10] left because I have picked 65. So, 65 will come down and a new node will be formed. But if you [00:10:16] remove 65, then this entire tree structure will disturb. So, what we will do, root will bring [00:10:21] down, a new node will be formed and then 65 will come and form a new node. So, that is the two-step [00:10:27] process. So, let me take the query for now and then we will see one more example. Afterward, [00:10:34] will explain about B plus 3 and then we will start heap and forest and end the trees. Then [00:10:42] we will jump into the scenario of the graphs. Yes, Anant. Anant, I have enabled your mic so you can [00:11:03] speak. Okay, fine. So, after a long time, Parambir, I am making you moderator. Okay, [00:11:30] so do handle the things. Just give me a moment. Okay, Parambir. So, if anyone ask any doubt, [00:11:50] anything so let me know i hope you will do it regularly in the class so okay so this was the [00:12:06] interesting aspect when we were deleting 17 then then there is a multi-label changes okay so these [00:12:15] type of problems are repeatedly asked in the examination where there is a two-level deletion [00:12:22] because this is one of the challenging thing in the beat. Now let me talk about another [00:12:29] interesting problem. So this is a, this is a order 3, order of this 3 is 3, order is 3. [00:12:45] So here we can easily see 3, 3. So if you talk about the 3, so the minimum allowed, [00:12:54] minimum allowed key is what? 2 and maximum is 3. Root can have 2 to 3 and other node [00:13:04] can also have 2 to 3. So this is about the child node. This is about the child. So key will be [00:13:14] 1 to 2. So this is your initial tree. Now a question arises, we want to delete 35. [00:13:24] So, where is 35? 50, 40, 35. Here we encounter. And what is the minimum child allowed? 2. And [00:13:31] here it is having 3. So, we can simply eliminate 35. So, here after elimination of the 35, [00:13:37] if you can check 20 and 35, 35 removed. So, 20 is here, no problem. Now, from this tree, [00:13:42] we want to delete 65. So, where is 65? Greater than 60, less than 70. Now, here we encountered 65. [00:13:56] So, now 65 says I am having the just minimum, so I can take it from my sibling, but sibling [00:14:02] is also having just minimum. [00:14:03] So, what we will do, 70 will be bring down, okay, 70 will be bring down, but when we try [00:14:11] to bring down the 70, then what will happen, this is having just minimum key and there [00:14:17] will be imbalance. [00:14:18] So, what we will do, we will merge these two nodes, bring down 60, okay, and then 70 will [00:14:26] go down and form a new node so here 70 has been come down forming a new node 65 was eliminated [00:14:33] and 60 come down to a company with 57 and this will be the arrangement so 60 come down there [00:14:45] will be a joint tree and then 70 and 75 will be placed now so these two things were the interesting [00:15:08] aspect. Now, I am not going into the detail of B plus 3, because all the property, okay. [00:15:15] So, B plus 3 is an extension, extension of B tree, all the property of B plus 3 is similar, [00:15:47] similar as b the difference difference if i say all the [00:15:56] information information are stored stored in the leaf okay so the information will be always [00:16:23] stored in the leaf so this means there will be a there will be a pointer from all the [00:16:41] internal node to the leaf one important second thing is that all the leaf all the leaf nodes [00:17:00] nodes are, all the leaf nodes are linked. So this means that if we are in the very low [00:17:12] level, so if I draw like this, so these are the leaf, so they are linked together. All [00:17:21] the leaves are linked together. So if let us say I am accessing some information here [00:17:25] and another demands come, so I will not go up, I will just move in this direction and [00:17:30] search okay so what will happen okay so there will be a link to a leaf where the information [00:18:03] is stored okay so two things are there one is all the leaf are interconnected that was [00:18:10] not there in the b tree and there will be always a link toward the root okay so for [00:18:17] example here i am storing 25 and here also you can witness 25 so this 25 is the address [00:18:23] thing and this 25 is the direct connection with the real data. [00:18:30] So all the data related information will be directly linked with the root and intermediate [00:18:36] node and root node will have a link toward that node. [00:18:40] So you will see the duplicate entries in the B plus 3 because 25 is here located also here [00:18:48] is 25. [00:18:49] So this is address, this is also the address, but this is a direct linking to the data. [00:18:56] So as we were discussing the memory organization, so here is the B plus tree, number of nodes [00:19:05] are there. [00:19:06] Now here there is index, if we want to access any index, so it will directly map to the [00:19:11] address. [00:19:12] In this way, fetching time is reduced to order of 1, fetch can be done in order of 1, but [00:19:24] of course search will require some time, so as log of n. [00:19:31] So if we are at some address, we can directly fetch it. [00:19:34] If we are at some address, we can directly fetch the information. [00:19:37] So basically, if you see B3 and B plus 3 are almost same, two things differentiate B plus [00:19:45] 3 from B3. [00:19:47] All the information are stored on the link. [00:19:51] This does not mean what we were writing 65, 35, anything. [00:19:54] In this tree, if I say how to form this B3 into a B plus 3, so I will just link this. [00:20:03] And here if you see 20, 45, 55, 58, 70, 75, so all these nodes. [00:20:11] will help a address copy okay so for example 58 here so of course here will be 58 somewhere [00:20:23] here it is let's say 70 here it may be 20 here it may be 45 anything because [00:20:29] maybe or that the b3 property is falling but this is linked this 20 is linked this 50 is linked [00:20:35] this 70 will be linked okay so all the leaf nodes this will be directly connected with the [00:20:41] data directly connected with the data. So, this is how we can easily differentiate [00:20:53] B tree and B plus 3 and therefore we may witness duplicate entry in the B tree. So, [00:21:01] this property we may witness or we should witness, there will be duplicate [00:21:16] n tree in the tree because we know that the internal node or root node will have some [00:21:28] value that value is also persist in the leaf and that act as a pointer to that data okay so [00:21:38] i hope you people get a visualization of how p tree looks like okay so let us start a new [00:21:45] stuff so uh for a bit just provide access those who have any query otherwise we will start the [00:21:51] second last thing in the tree the case is having some query because i'm having your mic uh uh yes [00:22:12] hello sir good morning yes good morning sir uh i have a query around b plus trees so as you [00:22:19] mentioned that all the leaf node will contain the actual data yeah and the address of the data will [00:22:26] be stored in either in root node or the intermediate node right yes so is it a some sort of [00:22:36] i mean address that will be pointing to the leaf node or we are talking about the indexing thing [00:22:45] that also indexing is basically the address when in our book index page is there the topic of [00:22:52] b plus t is located on this page so that is basically the topic name and its corresponding [00:22:57] address but the actual data is located on 271 page let's say so that that set of thing is there so [00:23:02] all the information that all the values that we are witnessing in the internal or the root node [00:23:08] will be the address only and there will be a pointer to the leaf for that corresponding address [00:23:16] okay so let's say if i delete any any data from the leaf node then the linkage link will also [00:23:25] so we will not delete the data we will delete that link initially so same deletion of the node [00:23:30] will happen and the link will also break and we know that now if there is no pointer to some [00:23:36] address so it is automatically eliminated in the memory okay okay yeah thanks okay and view of no [00:23:53] queries let us proceed uh sir one more doubt around insertion so when let's say if you want to insert [00:24:03] an element into the leaf node so how the traversal will go i mean we should have to start from the [00:24:09] root node and then the intermediate node and then eventually it will go into the leaf node or how [00:24:15] how that will happen okay so let's say we want to insert so we if you if you have seen so insertion [00:24:23] was primarily happening happening in the leaf part okay so when we try to insert so if we are [00:24:31] directly inserting in the leaf so it is direct pointer to it okay and it's in somehow if more [00:24:37] nodes are inserted downwards or some leaf level is pumped so in that case so there will be so either [00:24:43] the data will be that either we have direct access to the leaf or the access via the internal node [00:24:49] so whenever we insert a new node so we will we will just establish a connection as well okay [00:24:55] okay and the corresponding address as well in the root node and yes yes so in the root node [00:25:01] we will have same B tree structure, 25 and on the other side 25, but their copies are stored in the [00:25:10] leaf. So, 10 copies also persist, 2 copies also persist, 25 copies also persist. So, in that way, [00:25:15] the tree will be done. So, what I will do, not today, in the next class. So, we will see how [00:25:21] deletion and insertion is performed. So, it is easier than B tree. We will see. [00:25:27] okay thanks thank you sir uh yes good morning sir so uh at the end uh you have uh said that this uh [00:25:42] b plus tree like if there is a duplicate entry in the tree that will be acting uh like as a pointer [00:25:48] to the data yeah what do you exactly mean by that like if you can show any example so [00:25:52] actually i had not have those slides okay and the next class so uh basically what will happen [00:26:01] if i pick any tree so for example here is 57 okay and in the leaf also you will witness 157 [00:26:11] okay either the data directly reside in the leaf or if there is [00:26:16] uh internal load that holds the address so that will of course a pointer so it will be 50 kind of [00:26:22] getting so if you witness 50 in the root you will also witness 50 in the leaf if you witness 40 in [00:26:28] the intermediate root you'll also witness 40 in the leaf okay or if you witness something in the [00:26:33] leaves of course it is direct pointer to the address okay okay got it yeah if it is not clear [00:26:41] i agree so in the next class i will show you two three slides what how deletion and how actually [00:26:46] this b plus three look likes okay so that i will show now starting on and testing and easier thing [00:26:54] because we people have witnessed a number of complicated trees. So, the last one is heaps. [00:27:04] So, heap means that, so there is no foundation of who will go in the left, who will go in the right, [00:27:13] whether left is less than root or root is less than right, no foundation is there. [00:27:18] Just there is one foundation that if I say heap, so heap and heap sort we will discuss. [00:27:26] So if I say anything mean heap, what we have to remember, the node on the root will be [00:27:33] less than these two, whatever these values are. [00:27:38] Maybe this is high, this is low. [00:27:40] Then if I pick this node, so this must be less than these two nodes. [00:27:44] If I pick this node, then this must be less than these two nodes. [00:27:47] So if it is mean heap, then the minimum entry will be stored on the root. [00:27:52] the root will hold minimum value. Minimum of these two, minimum of these two, minimum of these two, [00:27:57] similarly minimum of these two and so on. If it is max heap, so maximum element will be stored on the [00:28:03] root. Maximum element will be stored on the root. So this is the one property and it allows duplicate [00:28:08] entry, it allows left should be greater than right or right should be greater than left. No worries, [00:28:13] just you have to remember one thing. The root will always hold the value that is if it is max heap [00:28:20] greater than its left child and right child, this will be applicable for all the nodes. [00:28:25] And if it is mean heap, the root will hold the minimum value [00:28:30] that is less than that of left child and right child. And important part is that [00:28:38] heap always try to maintain a complete binary tree. This is important property. There are some [00:28:45] questions where people confuse how to think. So, let us say we have a set of number. So, [00:28:51] if we form a heap in that case, we will try to close or be close towards the complete binary [00:28:59] tree. So, we will see some example as well for this. So, with the example, we will see. Now, [00:29:18] this one interesting thing is written unless stated otherwise we will assume h is maintained [00:29:24] in the memory by linear array that is also good so with the help of the linear array and that [00:29:29] property k 2k 2k plus 1 what we have we have understand in the sequential representation [00:29:36] mainly we will use array for representing the heap but if it is mentioned to use the link [00:29:41] so we can use for the link representation as well. A heap h is called as the heap or max heap if each [00:29:51] node n of h has the following property. The value of n is greater than or equal to the child. So, [00:30:00] equal sign is also, let us say this is 70, this is 60, this is also 70. So, this is allowed [00:30:09] because here it is written greater than or equal to and in case of b st m way tree b tree that was [00:30:17] not equal to it was greater than less than okay then accordingly the value n is greater than or [00:30:25] equal to the value of any of the descendants that is also important if there is another form this [00:30:32] This is called max heap. [00:30:34] This is max heap and the mean heap that we will use in the heap sort. [00:30:43] So mean heap is defined as the value n is less than or equal to value of any of the [00:30:49] node of child of n. [00:30:50] That is important. [00:30:59] Now let us see. [00:31:01] So see, if you see here 97, if you see this is greater than 85 and 95 or 88 is greater [00:31:14] than 66 and 55. 95 if you see here they are equivalent and here left is greater than right [00:31:20] no worries that is allowed. And 48, 95 is greater than 62, 77, 48 is greater than 25 and 38 and so [00:31:30] on. And what you witness that here also there is 38, here also there is 38, 95, 95 repeat entries [00:31:36] are there. Here 55 and 55 are there. But if you see we are trying to form a complete binary tree [00:31:42] structure here we are trying to form a complete binary tree structure here because it is using [00:31:49] same k 2k 2k plus 1 property and here if you see all the element in this array is completely filled [00:31:57] okay now the insertion in the heap is very easy okay insertion in the heap is or what i will do [00:32:06] i will try to reconstruct back this heap from this arrangement and see how the structure is [00:32:11] form very easy and this is max heap. Let me add one slide and show you. And then we will reconstruct [00:32:22] a heap as well. So, let me write down the numbers and then we will construct a heap from that. [00:32:39] So, numbers for 97, 88, 95, 66, 55, 95, 48, 66, 38, 48, 55, 62, 77, 25, [00:33:24] 38, 18, 40, 36, 26 and 24. Okay, just taking a short, short a minute break then when we are [00:33:41] resuming now. Okay, so let us start. So, now we have to construct a heap. So, simple property we [00:43:19] have to remember that root should always have the highest value. So, I have started with 97 [00:43:23] then following the complete binary so 88 will be the left child 95 will be the right child [00:43:31] no violation the property then comes 66 so it may be placed here okay then 55 then comes 95 so it [00:43:39] will be done here then comes 48 because we are also following the complete binary then again [00:43:45] 66 is coming no worries okay then 38 is coming 38 is here then we have 48 so 48 will go down [00:43:58] the next node is 55 then also no problem so 62 and 77 then here we have 25 and 30 because this [00:44:08] is a max heap so nowhere it is violating the property then 18 and 40 will come here 36 and [00:44:14] 26 will come here and 24 will become. And if you see here, so we are trying to as close [00:44:21] as complete binary tree. So, that is important, complete binary tree, we should be as close [00:44:35] to the complete binary tree. So, this is the algorithm primarily. So, just one case if [00:44:44] If you see here item, if it is less than or equal to 3 parent, then item will be accommodated. [00:44:52] So simple algorithm it is, now here is another how we can form. [00:44:56] So here 44 is coming, then 30, then if you can say when we are inserting, now one important [00:45:04] thing with this example that this was already a heap from which we have recreated it. [00:45:10] But if we encountered here, so 44 I insert no violation of the property, then I am inserting [00:45:17] 30. [00:45:18] So of course, it can go to the left because we have to follow the complete binary tree [00:45:22] property then comes 50. [00:45:24] So 50 will be first added here. [00:45:26] But this is violation because 50 is higher value so it would go to the rule. [00:45:31] So there will be a swap operation and this this swap operation for adjusting to the root [00:45:37] is called as the heapy find. [00:45:40] be buying operation to restore the property of the heap. Now next element comes 22. So, [00:45:46] 22 can be easily accommodated here, then comes 60. So, what will happen? 60 will be first [00:45:52] accommodated here, but this is clear violation. So, it will be swept with 30. So, 60 comes here, [00:45:58] 30 comes here, then 60 will be swept with the 50. So, 50 comes here and 60 goes up. So, this is the [00:46:04] resultant. And again, this operation will be a heapify operation. Now, next thing is the next [00:46:22] value that is 55 appears. So, 55 will go here, but there at no point of time, the higher value [00:46:29] will be on the lower part. So, 55 will swap 60. Now, I have swap 60. Now, 55 will be here and [00:46:41] 40 will be here. Then the next node come that is 77. So 77 will be initially added here, [00:46:48] but it will be swept swept and now 77 goes up and so on. Then again new 55 come and it will [00:46:55] be accommodated easily. So now a question that here arises, whenever we insert, so what we have [00:47:04] to take up in our mind. So the simple thing is that we will always consider that the root should [00:47:10] be the highest value irrespective of the left and right. At any point of time if you see, [00:47:15] so if you see 77 highest one, if you see this tree, this subtree, 55 is highest in this subtree, [00:47:22] 60 is highest in this one, 50 is highest. So, everywhere we are fulfilling the property of the [00:47:28] heaps. Now, we will see another thing. So, this already we have did. Now, deletion is very [00:47:44] interesting. Deletion is very interesting in here. So, we will always delete the node [00:47:54] from the root. So, see what if I delete 95, then during deletion, the last node will replace [00:48:04] the first node, the last node will replace the first node and or the root node and then [00:48:11] Then we will perform the heapifying operation. So, what basically we will do remove root, [00:48:18] remove root or not remove it is replace root with last element and restore the heap. Okay, [00:48:37] heapifying, heapify operation we will perform and restore the root. Okay, then again remove [00:48:42] it. So, what, what, what I am saying. So, after heapifying we are getting 85. So, first [00:48:47] First I have removed 95, next I will remove 85, then it will be replaced with 15, then [00:48:53] again restore things. [00:48:55] So if we keep on removing and storing these removed values, so what we will form? [00:48:59] We form an element arranged in descending order. [00:49:04] Similarly, if we keep on deleting, if it is a mean heap, and if we keep on deleting the [00:49:14] root and doing the heapifying then again next root will be deleted and next to next root will be [00:49:18] deleted. So, in that case what we will observe, we will observe a list will be formed that is in [00:49:24] ascending order and this ascending and descending order is nothing but this is called as the heap [00:49:29] sort. Heap sort is basically the iterative deletion of the element from the heap. So, [00:49:35] it will be always root and if it is mean heap, we will get ascending order. If it is max heap, [00:49:40] then we will get descending order and that is called as the heap sort. So, here it is saying [00:49:47] application of sorting that is heap sort. Suppose an array with n element is given, [00:49:51] a heap sort algorithm, sort a consists to build a heap out of a repeatedly delete the root. So, [00:49:57] first thing is that building a heap. So, it will simply build and then we will keep on [00:50:02] deleting the root, keep on deleting the root. So, deletion will be of course order of 1, [00:50:07] but heapifying will take log of n time, maximum. So, let me draw one tree and do the heapifying. [00:50:20] Just give me a moment. Last tree I will draw and I will try to perform the heap sort. So, [00:50:31] let us say we have 77, 55, 60. So, let us say we have a list of number and we want to sort. [00:50:43] So, form a heap then keep or repeatedly delete the root and we will get a sorted one. That [00:50:51] is the primary aim of the heap sort. 50, 30, 20. This was the tree and here it is 55. Now, [00:51:16] Now, I remove 77, it will be replaced with what 20. [00:51:21] So, resultant trees 20, 55, 60, 50, 30, 44, 55 and I have stored 77 in a list. [00:51:39] Now this is a violation, so what we will do, which one is highest, so this 60 will replace [00:51:45] 20 and resultant will be 60, 55 and when 20 comes here, so it will be replaced with 55, [00:51:54] 30 and here we will have 44 and 20, because same heapifying, then 60 will be eliminated. [00:52:02] So, 60 is eliminated with whom? With again 20, last node. So, then 155, either this or [00:52:09] that is totally up to you. So, we will prefer left one. So, here comes, then 50 will come here, [00:52:15] then 20 will come here 30 will be added here and we will have 55 44 because this node is already [00:52:22] removed and how this 20 comes here because 20 will be first swept with 55 then 20 will be served with [00:52:28] 50 okay then 55 will be removed so it will be now stored here and it will be replaced with 44. [00:52:35] So, the resultant tree will be 44, 50, 55, 20, 30 and of course, 44 was removed. [00:52:50] Now, there will be a swap operation. [00:52:52] So, resultant tree will be 55, 50, 44, 20 and 30. [00:52:59] Okay. [00:53:01] Now, this 55 will be replaced with whom? [00:53:03] It will be replaced with 30. [00:53:05] so 30 50 and that 55 comes here 44 20 so again swap will be performed the result entry will be [00:53:19] 50 30 44 20 then 50 will be removed and added here and it will be replaced by 20 so 20 30 44 [00:53:30] So, this will be swept, the result entry will be 44, 30 and 20. [00:53:38] Then in the next step, 44 will be replaced with 20, so 20, 30 and 44 will be placed here. [00:53:46] Then there will be a swept, so will form 30, 20, 30 will be added here, then last 20 will [00:53:54] be added here and this list is descending sorted. [00:53:58] When we will use mean heap, then it will be ascending sorted. So, this is nothing but [00:54:03] this is heap sort. So, I hope you people are getting the idea. And the last, the complexity [00:54:16] discussion if we talk about. So, we have talked the deletion is taking order of n. But heap [00:54:23] we find in each step taking log of n and if we are performing for n element, then it will [00:54:29] be n of log of n. So, it is as equivalent to the merge sort, quick sort another algorithm [00:54:35] that we have witnessed. [00:54:39] So, now the last topic for the tree is forest. So, as we know forest is nothing but the collection [00:54:48] of the tree. Similarly, same definition is applicable here. So, a forest is an undirected [00:54:53] graph in which two vertices are connected to at most one path. So, two trees, then this [00:54:59] the connection, this is connection. A spatial equivalent of forestry is an undirected acyclic [00:55:06] graph, all of whose connected component are trees. So, simply you can understand there is another [00:55:15] tree that is connected and then this is undirected, acyclic. A cyclic graph is called as the tree. [00:55:21] A cyclic graph is a tree. So, one more tree is remaining. So, let me take your doubt. If someone [00:55:39] has any doubt, then let me know. Otherwise, we will start the last tree of the tree segments. [00:55:45] okay no one is saying doubt or either all are in the festive mode or whatever I [00:55:53] think okay to us is asking something yeah one time we can show that deletion [00:56:00] hi sir am I audible yes yes yes you are getting so focus for the deletion one [00:56:05] more time okay this one yes sir this one so your [00:56:44] doubt is clear in this no no actually so when you remove the 20 like 20 you removed right so there [00:56:53] you do did the hippie fight to remove i have removed 77 by replacing with 20 the last element [00:57:00] okay and then we are doing ep5 so that it will go to its specific position so why we chosen that [00:57:13] last element 20 like because if you remember now we were following the [00:57:19] complete boundary tree okay so there should not be the gap while placing the [00:57:23] element in the array so best option is to pick that one and stop it so so we'll [00:57:29] always be picking the like the last element the leaf element something like [00:57:33] that to be yes that is the property that we have to be okay okay Arun is having [00:57:49] whether uh yes sir just hello yes sir please good morning sir good morning [00:58:01] sir can you again explain ep5 something i'm not on the ep5 is let's say keep 20 is replacing 77 [00:58:09] that you understand now 20 is placed on the root and what we have said that the maximum elements [00:58:16] should always be there on the root. And if you compare with the lower element, it is less than [00:58:20] both the element. So, we will prefer the highest one to swap it. So, 20 will come here and 60 will [00:58:26] go here. Now, when we see 20 again, we are having 45 and 55. So, it will be replaced with 55 here [00:58:32] and 20 will be here. So, 20 is now going to its specific position. So, that is called as the heap [00:58:38] define. Just place the node to a specific location so that there is not a violation of this property [00:58:45] of heat getting okay that means always root load always maximum value yeah root will be always [00:58:54] maximum that is only one property that we have to maintain in heat okay okay thank you sir [00:58:59] someone was also raising hand okay uh yes because so already your mic is enabled [00:59:15] uh no sir actually last time last one okay fine okay uh so what i will do [00:59:27] yes uh so number of interrupts are coming and in view of the festival as well uh so what i decided [01:02:41] so to to close here okay and red black tree we will just we will see the properties okay not [01:02:47] beyond that so that we will uh see in the next class so that probably happen on the next saturday [01:02:52] because tomorrow is Diwali [01:02:54] so happy Diwali [01:02:56] to everyone and we'll [01:02:58] close the session today [01:02:59] happy Diwali sir [01:03:03] thank you [01:03:04] happy Diwali sir [01:03:05] thank you