[00:00:02] The moderator, just let me know immediately, then I will provide him the privilege. So, anyone want to be a moderator, let me know. By raising the hand, I will add him in the meeting. Otherwise, let us start. We will do in the meanwhile, my last one. [00:00:37] So, in the last lecture, we have started the tree and we understand some basic concept [00:00:47] key, what are the tree, parent, sibling, so we started tree and we understand what is [00:00:59] binary tree, then we understand the complete binary tree, binary tree. [00:01:18] And we also explored the basic terminologies and we also explored the representation in [00:01:34] the memory, representation of tree in memory. [00:01:46] So it could be done in two way, one was link representation and another one is sequential [00:02:00] representation. [00:02:01] So sequential representation was simply that one, k was the parent 2k, left child 2k plus [00:02:09] 1, right child. [00:02:10] This you have to apply it everywhere and you can get back the location of the, all the [00:02:18] nodes in the array. [00:02:21] So yesterday we were discussing about link representation, then sequential representation. [00:02:28] So link representation was primarily done with the help of bi-directional linked list. [00:02:42] bi-directional linked list where the middle part hold the info and if you remember in the data [00:02:49] structure this is referred as previous and this is referred as next so previous hold the address of [00:02:55] left child and next hold the address of right child and first node obviously will be a specialized [00:03:03] node or that will be the initial node you can see and that has a special pointer that is called [00:03:14] start pointer and from here if we start. So this is the info, this left child, right child, [00:03:19] again, this is info left child, right child and here there is no left and right child. So this [00:03:24] is the leaf node. Again, f is the leaf node, no left and right child and here this e node is having [00:03:34] one left child. So right one is crossed or it is having a that is called as the null pointer. [00:03:40] So, these are the, this is null pointer, this is null pointer, this is null pointer and [00:03:51] so on. [00:03:52] So, this then we have seen this as well, how the things are represented in memory, so what [00:04:00] we found, the first address is stored in the root or sometime somewhere it is also called [00:04:08] as the start. [00:04:09] So, I am starting from here and I had an information about left and right child and if you go to [00:04:16] the 10th, so we obtain B that is a left child and again its left and right child are stored [00:04:21] on different location when we go to the 18. So, we found D that is a right child of B and both the [00:04:31] child's are, a left child of the B and both the child's are in the 0 indicating the null point. [00:04:41] we also seen there is a avail list that indicates that indicates the starting pointer [00:04:59] for the empty location in the memory then yesterday someone was asking why not [00:05:12] starting with 4 why starting with 8 so there is a reason that whenever any operation [00:05:24] release some empty space and this could be only done in case of linked list not in case of array [00:05:40] linked list it is added on the top of it is added on the top of the available list [00:06:04] it is added on the top of the available list so that's why so maybe initially we have all empty [00:06:11] but as different operation continues we have given dedicated memory but at last the deletion [00:06:19] was happened on the 8. So, this 8 also indicate location 8 also indicate the last deletion was [00:06:46] happen was happen at location 8. So, this is a simple thing when any operation release some [00:07:05] memory. So, its empty space is added to the avail list and why we are having 8 because [00:07:10] 8 may be the location where this release an operation was happened. Then the next [00:07:17] representation is called as the sequential representation. So, same phenomenon we will [00:07:22] all do. So, root will be stored at tree 1, first location, first location. So, I am following the [00:07:32] index 1, if you follow index 0, so you have to change accordingly, just reduce. So, this tree [00:07:40] will be stored at 0, left will be stored as 2 k minus 1, right will be stored as 2 k plus 2 k. [00:07:47] only okay so then null is used to indicate the empty tree so that already we have discussed [00:08:12] if there is empty space let us say i am storing the tree in a array okay and if there is a empty [00:08:18] space so that will be inefficient utilization of the memory so whenever your tree is complete or [00:08:25] near to complete we will prefer sequential representation because of its easier implementation [00:08:30] but when your tree is you can say sparse or not enough nodes, but having enough height. [00:08:38] So, then we will choose the length representation. So, this is how if we want to represent this tree [00:08:45] in the memory. So, this location is 1, this is 2k that is 2, 2k plus 1, 3. Now for this, [00:08:51] this is k then it this will be 4 5 there is no node on the 6 and this will be 7 and there is no [00:09:00] node on the 8 9 10 then on the 11 there is no node 12 and 13 no node 88 will be stored on the 14 so [00:09:12] what we found this space is empty this space is empty this is empty this is empty this is empty [00:09:18] So, so we required 14 location in an array even the array has 9 nodes and even if you [00:09:25] consider all the child's of the corresponding node, in fact, if we include null entries [00:09:30] for the successor of the terminal node, we will actually need 29 space. [00:09:36] But we were only engaging how much, only 9 entries, engaging only 9 entries. [00:09:55] So specifically the sequential representation of the tree with depth d will require 2 to [00:10:01] the power d element. [00:10:04] This much elements need to be stored. [00:10:07] And if your tree is here, this tree is not a complete binary tree or even you can say [00:10:19] that it is also not partially. [00:10:21] So this type of things you will and here if you see we are just only discussing about [00:10:25] the 14 entries and if let us say we are discussing about millions of entities. [00:10:30] So, lags of space will be remain unoccupied because of the sparseness nature of the tree. [00:10:40] Now, so next part that is traversing in the binary. [00:10:48] So we understand the representation, either it could be in the form of link or in the [00:10:52] form of sequential array with the convention of 2k, 2k, 2k plus 1 and dot dot so on. [00:11:01] Now, what is traversing? [00:11:10] So traversing is a mechanism of visiting all the nodes exactly once. [00:11:15] So there is difference between traversing and search. [00:11:20] So traversing or traversal is the mechanism visiting all the nodes exactly once. [00:11:48] So we have to visit all the nodes exactly one time. [00:11:51] So that is called as the traversal. [00:11:54] And what is searching? [00:11:55] is the operation of identifying a dedicated key. So, you can say that traversal is a extended [00:12:02] form of searching but better to keep it separate. So, traversal means that we are visiting all the [00:12:09] location and identifying what is stored and what is not stored. Just one key, I want to print all [00:12:17] the entries of the tree then I will use the traversal. And what is searching? Searching [00:12:30] is the terminal of identifying a specified key. So that is called as the searching. [00:12:51] Now traversal, so there are three types of traversals in tree that could be possible [00:12:56] that is pre-order, in-order and post-order. So, pre-order. So, usually if you see the tree, [00:13:07] so what it should be? There should be left child, there should be right child and there should be [00:13:13] root. So, this is called as the pre-order. I am using what? R is root, [00:13:25] root, this symbol just root, root, traverse means that whom I will visit. So, on each [00:13:31] node you have to take this decision, whether you are following pre-order, in order or post-order. [00:13:36] So, R will indicate root, L is left and RH I am saying is at right. So, when it is pre-order [00:13:47] then what I will do? I will follow root left right, pre means that root should come. So, [00:13:53] This ordering will depend upon the placement of the route, pre means route should come [00:13:59] first, in means route should come after left and post route should come after left and [00:14:05] right. [00:14:06] So that is the main mechanism that we adopt, pre-order means that process the route, traverse [00:14:12] the left in the predecessor and traverse the right in the predecessor. [00:14:19] That is root left right this decision we have to take every time that is called as the pre-order. [00:14:26] Then in case of in order traverse the left child traverse root and traverse right child [00:14:32] that is left root right this is called as the left root right and pre-order is called [00:14:42] as the root left right and to remember what is the thing pre means root should be pre [00:14:52] appearing in means root should appear in between and post means root should appear after left [00:15:00] and right so first i will process left then right then root so this is called as the left [00:15:08] right so this is called traversal or tracking so let us see this example a b c d e now here [00:15:15] Here I am following what? I am saying as determine pre-order. So pre-order is what? That is root [00:15:26] left right. So on the A, who is the root? A because we will start with the root root. [00:15:33] Then I will visit what? Root left. And if you see on the B, B is as well as a root. Then [00:15:42] Then I will go to the root left right, now left child is D and right child is E. When [00:15:49] this left is over then we will go to the this part, then what we will want C F. So, this [00:15:54] will becomes the pre-order, pre-order means that root left right. Now if you want to determine [00:16:00] in order, so in order says first left, first left. So, the in order first one will be what? [00:16:18] one will be what? D, because it should be what? Left root right, then D, then root is [00:16:27] B, then what we will cover? E, this subtrees cover, then we will go to A, then there is [00:16:39] no left. So, C will be covered and F will be covered in the last. So, this will become [00:16:43] the in order that is left root right. Now, if you want to determine the post order, what [00:16:55] What is post order? [00:16:57] Left right root, left left, then E, then B, then F, then C, then A. [00:17:09] So this becomes the post order. [00:17:11] So what the significance we found that in pre-order first node will be always the tree, [00:17:17] first node will be always the root and in post order last node will always the root [00:17:24] and in order the root will appear in between the left and right chain. So, root is appearing [00:17:29] in between the left and right chain. So, this is the thing. So, let us do some more examples [00:17:35] to understand the traversal in the tree. Then we will try to construct back a tree from [00:17:40] a given in order post order notations. [00:17:44] So for getting back the tree, we need, there are two possibilities, pre plus in or post [00:17:53] plus in. [00:17:55] So if we have these information, then we can retrieve the tree as well. [00:18:04] Or let us say, I want to do the sequential representation here. [00:18:10] So I will just maintain the pre-order and in order in an array and we can fetch back [00:18:15] the tree without following the notations of what k, 2k, 2k plus 1. Simply what I will do, [00:18:24] I will determine pre-order, I will determine in order and push them into two different array. [00:18:29] Now, whenever the tree we want to regenerate, then using these two, we can get back the tree. [00:18:36] So, that we will see with an example, but let us do some more example for pre-order, [00:18:40] in order and post order okay so everyone just check whether this pre-order in order and post [00:18:48] order what i have written is correct or not okay so giving you five minute just do it then i will [00:18:53] solve this problem and one or two problem i will also do okay so everyone just do this [00:18:59] uh yes mohit so you raise the hand yes you are asking for the third okay okay so i will i will [00:21:04] make you moderate thank you thank you man just give me a minute okay now you can provide mic [00:21:18] access to other as well okay so i will take queries okay but uh let me solve this problem [00:21:25] in chat someone has also solved this okay good so uh let me do this okay someone has solved [00:21:34] and i will take queries okay after some time now talking about this whether these are correct or [00:21:44] not. So, first one is pre-order. Let us do it. So, pre-order says root left right. So, [00:21:52] every decision we have to take. So, from here we will start. So, root then we will go to the left. [00:21:58] So, b is also the root of this subtree. So, I am covering root then root left right. Now, [00:22:05] here we will only have root. So, d now in this part we will go. So, again e is the root [00:22:10] and f. How left is the, so root left then right, c is also the root, then left is 1g, [00:22:21] then h is root, then j is root, then l is root, then k. So, that is every time what I am following, [00:22:32] root, left, right, root, left, right, root, left, right. Everywhere just think about just [00:22:41] simple term. So, you can easily obtain and if you see the answer a, b, d, e, f, c, g, h, j, l, k. So, [00:22:49] that is correct. Now talking about the in order. In order is what? Left, root, right. So, here a, [00:23:00] no left, no D. Yes, this is the last sign in the left. So, I will start with the D, left, [00:23:07] left root is B. Then I will come to E. So, I can consider E, but it is having the left side. So, [00:23:16] left root right. So, F, E. Then we will go to the A. So, left is done, then we are going to the A, [00:23:24] that is root. Then on the right here we come, so c, but c is having the left child, so left [00:23:31] root right, so left is g, then left root c, then here we will go to the right, so right is h, [00:23:44] so it is having what, left child j, left child l, so l, j, h, k, so this becomes the in order. [00:23:53] Now we will talk about the post order. Post order says left right root. So left left and here we will start with the D left right. Again this is root so I will consider F. Then E is this root. Then B. Then I will jump to the this portion. So left is G. Then I will go to the H. It says left left. [00:24:28] So, L, J, K, then H, then C. What we found? C is then, sorry, K, H, C, A. So, K, H, C, [00:24:53] A I am writing here. So, left. So, the basic thing is that whenever you obtain a tree, [00:25:03] okay. So, what we will primarily check? We will primarily check, we will in case of in-order [00:25:08] and post order go to extreme left. Go to extreme left and then take the decision or simple [00:25:20] thing is that on all the nodes just do not forget about the tree. Consider only these [00:25:26] three nodes and start thinking what is the property left root right that is in order. [00:25:34] So here is left is b and c is, so left root right. [00:25:40] So I will come to this node. [00:25:41] Now whether I will consider this or not because now when we consider b then this subtree will [00:25:46] be obtained. [00:25:47] So left is d, there is no more child. [00:25:49] So we will consider d and root is b, again consider e is another root but when we reach [00:25:56] to the e then this is another subtree. [00:25:59] So here we will consider f, e and another, there is null child. [00:26:04] we will jump to the A. So, just consider trio and this trio consideration will continue when [00:26:13] when we reach to the label where there is no further child, then we will start writing it. [00:26:19] In case of pre-order, pre-order says that it should be root left right. So, immediately you [00:26:24] can consider the first node that you encounter. So, very simple example. So, if you consider the [00:26:33] pre-order so that is root left right can i consider post order so it says left right root [00:26:42] and in order is left root right so here it is okay so this is simply one more example if we can see [00:26:56] now for pre-order will be a root then left that is also a root then [00:27:03] left right. So, A, B, D, E and last one is the C, that is a pre-order. In order means, [00:27:13] in order means that first go to the left extreme left, so that is D, in order is left root right, [00:27:22] left in root and then right okay so this is in order so this in order pre-order and post order [00:27:34] you can apply on different different nodes considering the try of left child right child [00:27:39] and root okay similarly here if we want to determine the post order if you want to determine [00:27:48] the post order okay so what you can do that is left left then now we have left right root left [00:28:03] then come to the right then root so here it is so that is a post order okay so what we have did [00:28:12] if we want to store this six node we can use pre-order and in order or pre-order and in order [00:28:18] and then we will understand how we can retrieve back a tree. So how we can retrieve the tree back [00:28:25] using the combination of post order, in order, post order, pre order, in order. So multiple [00:28:32] examples I have put. So here it is marked wrong. So why this is wrong? Let us check this one. [00:29:02] just a minute and so now if we want to check the pre-order thing okay [00:30:09] so let us see why this pre-order says that root of course one will come then left that is two [00:30:19] that is also a root then left that is four that is also a root then seven that is also a root [00:30:29] left is not there then we will consider right then we will come back just give me a minute [00:30:40] sorry for the delay okay number of interruptions are appearing today so let us continue okay okay [00:47:00] so the next was this one we were discussing about the determination of the pre-order why it is wrong [00:47:08] I have mentioned. So, we what we found that it is first we have to visit the [00:47:14] route. So, that is one then next one is the left that is also the route then 2 then 4 then 7 [00:47:22] then 9 then we will go to the 5 then afterwards we have a right. So, that is first because it is [00:47:34] pre-order, so root, so this is 3, 6 and 8. So, if you compare both 1, 2, 4, 7, so it was correct. [00:47:42] So, just I have intensely mark a line over it. Now, a question arises if we have pre-order and [00:47:54] post-order, so how we can generate the tree. So, let us see some simple example, even we can start [00:48:01] with this one. Now we have, we have pre-order and post-order. Just I will write down the content. [00:49:06] So, let us reconstruct back the tree from the combination of either pre-order or post-order [00:49:13] or post order and pre-order. Now, we have pre-order that is 1, 2, 4, 7, 9, 5, 3, 6, 8 and [00:49:40] in order because in order is mandatory. Either you are using post order or pre-order but [00:49:47] you should have in order that is 7, 9, 4, 2, 5, 1, 3, 6, 8. So, pre-order we know that [00:49:57] first node is always the root node and from the in order we will identify it will hold [00:50:03] left child and right child. So, here we have one, so left child are 7, 9, 4, 2, 5 and on [00:50:14] On the right we will have 3, 6, 8, then this node is done, now we will shift to the second [00:50:21] root. [00:50:22] So second root is here and if you see second root, so left is this one and right is this [00:50:28] one. [00:50:29] So next step will be 1 and second root is 2 and here we have left that is 7, 9, 4 and [00:50:37] On the right we have 5 and this will be as it is 3, 6, 8. [00:50:45] Then the next root if you see is 4. [00:50:48] So 4 is where? [00:50:49] Here and 4 left are 7 and 9 and there is no right child because already these nodes are [00:50:56] visited. [00:50:57] So 1, 2, 3, 6, 8 and here we are having 4, 7, 9 and this one is 5. [00:51:11] Then the next root will be 7. So, among these two, 7 is the root, there is no left child but [00:51:17] there is the right child that is 9. So, what we will get? 7 will be this and 9 will be its right [00:51:25] child. 9 will be its right child. So, now then we will identify next root that is 9. So, 9 will come [00:51:33] because if you see here both the nodes are already traverse. So, 9 will remain intact. Now, the next [00:51:38] root is 5. So 5 here there is if you see 5 both the things are already traversed so nothing to [00:51:45] worry. Now the next node is 3. So 3 will be here and 6 and 8 are what? Right child. So 6 and 8 [00:51:52] will appear here. Then after 3 there will be the node 6. So 6 will be there and 8 will be the right [00:51:59] child. If you go to that already the nodes are traversed and we will get back the structure. [00:52:03] And if you compare with the previous one, 1, 7, 1, 2, 4, 7, 9, 1, 2, 4, 7, 9, 1, 2, 5, 1, 3, 6, 8. [00:52:13] So, we are getting back the original tree by using the, these two things. [00:52:17] Or what we can do, we can in two arrays, we can store in order and pre-order. [00:52:21] And using them, we can retrieve back the tree. [00:52:24] So, this is, this traversal is also efficient or essential when the tree is very sparse. [00:52:31] So, we can use two arrays for storing them and its storage is not likewise k2k, 2k plus [00:52:38] 1. [00:52:39] You can simply store what? [00:52:41] The same order, root left right or it is pre-order then root left right. [00:52:46] If it is in order then left right root, we can store in two different array and get back [00:52:50] the tree. [00:52:51] So, let us reconstruct this tree using post order and in order. [00:52:54] So, post order, post order is 974. [00:53:09] 5, 2, 8, 6, 3, 1 and in order, in order is 7, 9, 4, 2, 5, 1, 3, 6, 8. [00:53:33] Okay, slow down, we are constructing the tree from the post order and in order. [00:53:38] So, we know that in post order, the first node lie in the last or the root node lie [00:53:42] the last one then if you see one so left child this one right child this one okay seven nine [00:53:53] four two five three six eight then next node is three okay so next node is root is three [00:54:06] so if you see three so here three left already covered right is there so one seven nine four [00:54:14] 2, 5 and here we have 3. Then if you see second node is 6, second root is 6 after 3, 6, then [00:54:25] 8, then we are having 2. So, now this will be divided. So, what we will get? 1, 3, 6, 8 and [00:54:36] here we will get 2 and if you see 2 position is 7, 9, 4 and on this it is 5. Further we [00:54:47] will see the next root that is 5. So, if you see 5 both ends are covered then we will see [00:54:53] this next node that is 4. So, what will happen? 1, 2, 3 and 4. So, these are the left child 7 [00:55:21] and nine seven and nine are the left child and four is here okay then next node and so on so [00:55:27] what we are seeing that when we are using pre-order and in order combination we are generating the [00:55:33] tree from left to right and when we are using post order we are generating the tree from the [00:55:38] right to left okay now i will take your queries then we will start the binary search tree the next [00:55:43] think that okay i have enabled your mic okay okay yes because anyone can start asking the questions [00:56:10] yeah i have enabled your mic uh sir can you go back to the last uh example sir just to control [00:56:19] this one yeah yeah uh can you just let us know how this uh turn that happened from one to five [00:56:26] and then i mean from our start of the route like when you said right we decide the new road [00:56:31] itself on the two that is the new one how it begins so yeah so i have just start picking the [00:56:39] roots from the post order because we know that the last node will always the root so one then [00:56:45] next root is three so see the position of three in order so it says that these are on the left [00:56:50] and these are on the right but one already track so we will not consider the left child we will [00:56:55] only consider the right chain if i encounter a node that is already traverse okay or that is [00:57:02] already covered so i will stop movement in that direction so for three i will not go to the one [00:57:08] i will just only consider the six and eight uh okay so in case uh just to confirm sir in case [00:57:16] i mean how to confirm this that the tree which is formed right after this has got the relative [00:57:22] information which can cover maximum of the tree uh relevance i mean in this way uh is there is [00:57:28] any way to understand or calculate as you will get same tree you will get exactly same tree what [00:57:34] we have uh earlier from which this post order and in order are calculated so there will be no [00:57:40] difference okay okay okay so so uh if you are getting same tree so there will be no loss of [00:57:48] information or anything you are retrieving back it okay so in case the equivalence is there so [00:57:53] there is no lost information yeah yeah okay if you are following same process and if you have [00:58:00] exact information about pre-order in order then you will retain back that uh but in case of this [00:58:05] sir that is pre-order the right most which is like one three six eight it is a invalid rewrite [00:58:11] it's a skewed one the skewed one no worries now because here we are not talking about memory [00:58:18] efficiency here we are just storing the element in the one two three four five six seven eight [00:58:22] nine locations not following k2k and other stuff but still we are getting back the tree so in terms [00:58:28] of memory efficiency we have very much sparsity so you can use two array and store these information [00:58:33] and retrieve by the tree whenever required okay i mean why i'm just putting that question again [00:58:40] because yesterday we told about that uh if the tree is having a left function right which is [00:58:45] like you have to write movement that is a valid tree and this one this is a pre-order which is [00:58:50] the right most seems to have a right life you can say right life which is on the one three six eight [00:58:57] as a till root sorry as a till leaf actually so was it a was it an invalid tree or it's a valid [00:59:03] tree itself no so this is so this tree is valid so not if this tree is not complete tree you can [00:59:09] say but this is valid okay this is valid because here it is not already although [00:59:18] yes i just got your point okay let's say this is a skewed tree this is a skewed tree but this is tree [00:59:24] this is skewed toward right and left and there is imbalance in there are number of imbalances here [00:59:28] but of course this it is a treat so it is not right or wrong tree it is a balanced tree or [00:59:33] unbalanced tree so here the complexity of searching may reach toward order of n [00:59:37] and if it is perfectly balanced so it will reach to a log of n i think so balanced tree and unbalanced [00:59:43] tree not wrong tree and right tree i mean maybe the terminology i'm kind of hindering in there [00:59:50] but i'm just tired of confirming whether because yesterday's concept is kind of con [00:59:56] in making a collide here and that's where just sort of confirming sir okay okay thank you no [01:00:03] no no so still if you are just because maybe this doubt is uh coming yeah i mean yesterday's only [01:00:09] uh that's the discussion was there where you have it is as a left uh less left distribution right [01:00:15] that it goes to a uh correct combination okay correct generation of the tree itself [01:00:21] but right now we see the right one which is already falling to one three eight [01:00:25] which means are we following in a correct tree tree formation itself or it's a skewed or it's [01:00:31] invalid tree so then that's where i'm just so yeah okay so invalid uh you cannot say you can say [01:00:38] skewed so if i'm adding node here and here so this is right skewed and on that yesterday i was saying [01:00:45] it should be toward the left when it is a last node having one check so that was complete tree [01:00:51] so i'm not talking about completely we are only dealing with binary a complete or partially [01:00:56] complete tree sir that you explained yeah complete or partially complete but this tree is sparse if [01:01:01] you can see there is no node here no node here no node here no node here no node here so this [01:01:05] is a sparse so this is but not a complete or partially complete tree so still it will be [01:01:12] valid yeah yeah the tree will be valid but not complete and so it will be not memory efficient [01:01:17] to store this in the array but this is trick yeah and what kind of use cases we used to have for [01:01:25] this i mean is it the same uh ram use case that we talked about that uh efficiently so that uh [01:01:32] that use case we will talk about but what will happen if we need extra space for storing the [01:01:37] information where the value is already not stored so likewise in the same on the blank space yeah [01:01:43] so blank spaces will be there if you try to push into the memory okay okay so oh sorry for taking [01:01:50] a few minutes no no worries maybe others are having same doubt now that's why i'm happy to [01:01:55] yeah hello sir good morning good morning sir i have a doubt regarding this tree or data structure [01:02:06] as you mentioned that it's a non-linear data structure but then we see that we are storing [01:02:11] the data points in the linear data structure like array or linked linked list so i mean what's the [01:02:19] benefit we will get if we are still storing. So your memory is simply the from 1 to 1 0 2 3 as [01:02:28] I was taking the earlier example. So it is your memory is you can say best represent the array [01:02:33] hitting. If an array as you store the element similarly your memory is also available [01:02:39] but these data structures are the logical organization. So this is not physical organization. [01:02:45] okay this is a logical organization where we bound certain set of rules so that we can efficiently [01:02:51] access and do the insertion deletion and traversal faster so every time when we say data structure [01:02:57] it does not mean that we are physically doing something it is a logical organization of the [01:03:01] memory to enhance the speed of insertion deletion traversal and searching okay so under the hood [01:03:08] it's all array yeah yeah so it is of course will be form of array or it will be form of [01:03:15] linked list and no third form so stack is one logical arrangement q is another logical arrangement [01:03:21] tree is another graph is another disjoint set number of data structures we have but [01:03:26] all are the logical arrangement because your physical memory is zero to one twenty three [01:03:31] there is no jumping and others they are available to you and sir i have another question when we say [01:03:37] sparse tree so so it means for any given sub tree if there is a null pointer or if [01:03:46] we don't have any child in that sub tree then we will call it as sparse means [01:03:52] that it is you can say a positive completely where the number of nodes or [01:03:58] or all the nodes are not having both left and right child or most of the [01:04:03] nodes are having only one child so that that kind of situation it is okay so if there is no child [01:04:10] that means we have the null pointer as we discussed yesterday yes yes yes okay and sir i have another [01:04:17] question from yesterday topic when you were explaining about the binary tree representation [01:04:25] so in in linked representation you mentioned that we have three variables if i say it correctly [01:04:34] like info root and avail yeah so these three variables needs to be initialized yeah yeah any [01:04:40] problem statement so we have to have some root and avail and then we can start and form the [01:04:46] representation so avails it's a you can say complementary you can skip avail so you have just [01:04:51] root information okay and then you can start and and afterwards you will get left child [01:04:57] right child info part is the information content okay and and others are the pointer for the left [01:05:03] address right address and so on okay okay okay sir thank you yeah i think sir kumar pande [01:05:14] good morning sir good morning sir basically uh as i these are the things of like traversal right [01:05:21] pre-post and in order yeah so basically sir uh my doubt is like pre-order which is fine basically [01:05:28] we visit the root node then left then right but in post and in order we are visiting like for the [01:05:33] post order first it is right then root and then uh left that is for post order is uh left right [01:05:41] root yeah so basically sir how we can do the traversal without visiting the root node that [01:05:46] my question because uh if we want to traverse we have to start from the root right because we have [01:05:52] the only this that pointer to be started with so i'm not getting that how can we start with [01:05:58] the leftmost without visiting the root okay so when i visit the root and i'm saying i'm using [01:06:05] post order okay so immediately without uh let's say i had a operation of printing the root value [01:06:11] okay just print the info part so i will not engage the print function unless there is a [01:06:16] child on the left side or right side so i will just go down down down to the left most part [01:06:22] if there is no child then i will initiate the print statement and then i will write print d [01:06:27] or print f and if it is pre-order then what i will do i will go to the root first print it [01:06:32] then check the left and right child then print them then check left and right child then print [01:06:36] them and so on getting okay okay so basically means it is like we visit the root node but we [01:06:42] don't look into the info part of it unless what type of criteria we are following okay so basically [01:06:49] then it is i think the violating the statement that you have given that uh every should every [01:06:54] node should be visited exactly once so basically if we do post order then we are visiting like twice [01:07:00] because once we visit then we don't see it and then again we come and see to print it out yes [01:07:06] yes yes yes yes so basically in post order and in order there will be just redirection [01:07:12] as per the policy unless we are meeting the policy then we will do the print statement [01:07:17] if this is just example yeah yeah so so basically it's like the violation of the [01:07:23] definition that is what i'm trying to get because it is like exactly once so in post and in order [01:07:29] we are not doing exactly once it is like exactly more than once yeah so i'm totally getting you so [01:07:39] uh let's say um i'm taking a simple example if i visit to your house okay and i just ask where the [01:07:50] look the location of uh monies or something is located you just redirected okay i don't bother [01:07:56] about you or perform any operation or even see you just get a redirection that you should [01:08:02] not go there you should go to the left child rather than going directly to the root so [01:08:07] that redirection is happening actually when you go for the implementation it is stacked [01:08:11] based all these post order period are stacked based so root and left child other things [01:08:16] are pushed down into the stack and we are processing the top element always so top element [01:08:21] will be the left side okay so basically my concern is not not to that my concern was just only with [01:08:27] the statement so it it should not be like exactly once right because uh traversing or visiting means [01:08:34] that we we are performing the print operation you can say not the redirection decision okay [01:08:40] not the redirection decision yeah okay thank you sir that was that was like it was a bit confusing [01:08:45] no no good good question it was yeah hello hello good morning my first question is the page number [01:08:58] seven it has a calculation to find the the level that log n plus one can you just go to that page [01:09:06] seven this one seven seven it is twelve yeah go back back seven is not there seven number slide [01:09:18] i will open okay okay i'll just tell you that dn is something like log n plus one okay but in this [01:09:24] case you see this one this n right n will be the number of elements so number of elements for [01:09:30] complete binary tree will be always odd numbers yeah right so that case if i to take the log n [01:09:38] plus one right it is something like n plus one together and then take a log on on that because [01:09:43] because if i see that level one let us see two to the power uh zero so that's right that is one [01:09:50] yeah if i take two to the power uh one right that is two plus one that's three yeah yeah right but [01:09:58] here thus the given is something like log two n plus one not the bracket okay i guess in yesterday [01:10:06] slide it was so uh yeah we'll we'll check also there might be some uh bracket issue or something [01:10:12] i have yeah okay so yeah yeah so the second one is regarding the depth yeah depth is similarly [01:10:19] sir you have given two to the power d plus one but the question is the number of elements will be [01:10:25] always in odd numbers so if you see two bit but d plus one it will be always an even number so [01:10:30] is it okay or so see so this much memory you will engaged okay although you will not occupy so you [01:10:37] you may occupy some odd ones so one or two may be used by later program okay so that is this is a [01:10:45] number of node in the depth d there is a simple representation here okay and third question is [01:10:51] regarding that evil let's see if one element does not have any parents right yeah yeah so that case [01:10:58] evil but because in real life scenario in database like your like parents or indexes right we never [01:11:07] use anywhere there is no parent sir is there any real life scenario wherever we use the element [01:11:12] having no parent but we travels to that element no so that is not possible because linking is [01:11:19] should be there now so if there is so in database if you go with the stack implementation on anywhere [01:11:25] if there is no pointer to the parent okay so that will be you can say that node is [01:11:31] automatically removed because we cannot access that there is no access path node will be killed [01:11:36] exactly if i move the manager means it is completely moves like subsequent employees [01:11:42] okay yes yes okay sir thank you yeah good morning good morning sir good morning [01:11:51] sir what do you know how to determine the size of the area where we are storing the tree so [01:11:56] that that is this formula now two to the power d plus one that was given this much number of [01:12:04] element we need so this much storage is needed okay okay yeah so how it is 20 answer here [01:12:14] so uh 29 means that if we are considering all the child and other stuff okay okay then one [01:12:20] okay so but if you go with the formula so then all the null pointers will be stored and everything [01:12:25] will be stored then only we can take a decision over so d is the number of node here this is the [01:12:32] the depth depth okay yeah thank you sir i have another question uh so basically in the linked [01:12:47] list when we delete an intermediate node we basically join the previous node with the next [01:12:54] node yes yes skipping the deleted node yeah but what will happen in case of tree if we delete [01:12:59] let's say the intermediate sub tree so the underneath whatever nodes we had [01:13:06] that that will become orphan so no no so that is not so we will see the [01:13:11] deletion so whenever let's say I want to delete a root node so it's left child [01:13:15] or right child will take over its position and the pointers will be [01:13:18] adjusted accordingly so we'll see in later on when we discuss binary such [01:13:23] tree and other tree so there are different mechanism of deletion it is [01:13:26] not simply remove it we have to replace it by in order successor pre-order pre-order successor or [01:13:32] anything number of things we have to do then only we can go ahead but in a way we are storing the [01:13:37] tree into linked list format right so let's say i want to delete b in this example i want to delete [01:13:45] b so in while doing the deletion in tree we will not immediately remove b we will remove b with its [01:13:52] immediate uh in order previous successor and then we will remove it so in tree that the [01:13:58] relation is not there it is replacement so we will then we will be removed so there will be [01:14:05] no change in the links yeah okay fine so you will be covering the deletion the deletion is important [01:14:12] insertion deletion every tree you will find how insertion and deletions are done okay thank you [01:14:18] i'm having also one doubt yeah yeah when say slides seven where you have shown the table [01:14:31] that avail basically right it's regarding deletion yes regarding deletion only let's say eight [01:14:38] that somebody has asked questions now only if there is no parent uh i mean id let's say eight [01:14:45] wherever you have written eight there's nothing mentioned as a parent right yeah yeah then how we [01:14:50] can mention the left whatever mention nine okay i mean if there is no parent then how the child [01:14:56] will be there no so this is just a linking so yeah the avail pointer or the empty space are linked in [01:15:04] a one-way list okay so there is info part info part is null and the pointer to the next so this [01:15:10] is an aggregated of all the empty space in the memory so whenever memory is needed we will delete [01:15:16] from the top give give it to it when there is deletion or available memory we will add it on [01:15:21] the top so insertion and deletion will be order of one so that is thing is i'm getting i had just [01:15:27] information about how much available space is there and all are linked if i want to use 10 [01:15:33] space so it will provide you 10 locations not consecutive location here and there but they [01:15:38] are linked together if it is not linked then there is then we have to explicitly search all the empty [01:15:44] spaces and then we will find some of them so that's why this linking is established info part [01:15:49] null but there is a pointer so the meaning nine is that there is another one where the empty space [01:15:56] is there and whatever is mentioned with the nine the top one is eight there is no info part then [01:16:02] the next available space is available at nine next available space is available at four next is at [01:16:07] 14 then 15 then 16 and so on but sir we have mentioned left this one that's the basic doubt [01:16:14] i mean no no so that is not this is a single address pointer we will always hold okay actually [01:16:19] what happened we are directly covering the algorithm in data structure the um the avail [01:16:24] thing is discussed in detail so it is always a unidirectional not bi-directional linked list [01:16:31] so i mean this we have written as a part of this list but it is [01:16:34] is but but but it is explicitly it is something this is separate separate purpose yeah yeah [01:16:41] hello sir yes yes yeah sir uh actually my uh doubt is regarding this as well only so you just say [01:16:56] that um it's uh deleting from the uh top and if there is any memory uh space empty then it is [01:17:04] coming to the top yes suppose i have i have uh four memory indexes empty right so um then after [01:17:17] that suppose that fourth place of memory is uh free so fourth will be used fast and fourth will [01:17:25] be uh if if forth coming after those staffs then forth will be used first right yes yes yes yes [01:17:34] so it's like uh creating like a stack means yes yes yes behind the avail there is a stack always [01:17:42] yes okay and sir one more question that regarding b complete tree that uh for the previous class [01:17:53] so yeah could you please go to the go to the last pre-order post-order in order uh three [01:18:01] just go to the last slide this this this last last slide last one last one so yeah this is the last [01:18:11] name uh okay then so uh suppose you ask for a uh creating a complete b tree so you told that um we [01:18:21] we skip that right one. And if there is any leaf that is on the empty one, any leaf, so [01:18:34] we need to put it to the left. So here sir, if some leaf is there at upward, like it is [01:18:43] 44 after the 33. So, if I create a complete B tree, then 44 will be that left one, means [01:18:53] we need to shift all the nodes to the left side, means suppose that there is 10 and 12. [01:19:00] So I am just saying, if a complete binary tree is a definition of something and here [01:19:06] this structure is already present, we are not going to modify any structure of the tree, [01:19:11] we are just doing a traversal, pre-order, post-order, in-order. We are not modifying [01:19:15] the structure. This tree is there, you have to accept and you have to apply all those three [01:19:19] things. And if I want to create a… So, suppose there is a question like [01:19:24] this is the structure. If you create a complete B tree, then after traversal what will be there? [01:19:30] Okay. So, if complete B tree is there, [01:19:34] we need to make it a complete B tree and then traverse for the pre-order. Suppose there is [01:19:39] question like this okay so let me let me show you an example because the already existing tree you [01:19:44] cannot modify anything okay so i will create a complete tree so one three then four will go here [01:19:52] then seven then eight okay then nine then ten then eleven will go here 12 will go here 14 will go [01:20:03] here and 15 and let us say 16 is also existing 16 will go okay so now this is complete binary [01:20:10] agree now if i want to do a pre-order of this one so it is one then three then seven then eleven [01:20:19] twelve then eight fourteen fifteen four nine sixteen and ten okay so this will be the pre-order [01:20:35] Yeah, but this tree is not partially complete Bt. [01:20:43] This is complete Bt tree. [01:20:44] This is complete Bt tree. [01:20:46] Yes. [01:20:47] So, you told yesterday there something the partial tree also. [01:20:51] So, you need to modify that. [01:20:53] Partial means that, let's say I have just removed this branch. [01:20:56] Remove this branch and make the 16 to the right one. [01:21:01] Yeah, 16 here. [01:21:04] Yes, and remove this one. [01:21:07] yeah so uh if we need to traverse and uh with the complete means if we create a complete [01:21:14] b tree from from this partial tree then we need to shift that 16 to the no no no no so [01:21:23] converting an existing tree into complete trees is uh not suggested because there then you have [01:21:29] to do release and insert some number of operation you have to perform directly it cannot be shipped [01:21:33] okay okay okay okay thank you sir good morning sir good morning sir [01:21:50] I will create first node one but who are left [01:22:22] and right check this information will be given from the in order so that's why these two [01:22:26] combination is needed okay thank you sir sir one more doubt uh yes just uh just uh go to the slide [01:22:39] number 13 that is uh you write one uh item with t of 29 that part this one yeah yeah this one uh [01:22:53] sir how there the tree is 29 it should be the 15 right means if it is if we come complete [01:23:02] the tree okay complete the binary tree means it is actually required if we consider all the successors [01:23:13] okay all the left and right child that are although empty but we are considering so it will take 29. [01:23:18] Okay. So, if there is a question in MCQ like that, so how many that successors will be there? [01:23:28] Okay. That will be explicitly mentioned that you have to consider the null pointer as well or not consider. [01:23:34] If not consider, then 15 is the answer. If consider, then 29 will be the answer. [01:23:39] Okay, sir. And one more question that is regarding the depth. [01:23:43] So, for the depth, we only calculate the edges, okay? [01:23:48] So, do you need to calculate that root also? [01:23:51] Means here, we can consider the depth is 3, right? [01:23:55] 1, 2, 3, yes. [01:23:57] And edge can be represented what? [01:24:00] 47, 77 edge, 77, 90 edge, and 90 and 15 edge. [01:24:06] Okay, so that is the 3 edges. [01:24:08] So, edges can be represented with the help of pair of vertices. [01:24:13] yeah and so the depth so depth will be the three right uh so in the depth calculations do you need [01:24:20] to uh calc means add the root root also means here uh three plus one or only three what will be the [01:24:30] answer for the depth calculation sir what means for the depth calculations we need to include [01:24:39] that root also only that ages only the ages or x the nodes accept the root [01:24:47] except okay i guess we are good to close uh although this class was a little disturbed [01:25:03] yes yes sir one more uh vikash anand then i'm just yeah uh sir so to recreate the binary tree [01:25:12] from this in-order, post-order, pre-order, we need either in post or in addition with [01:25:20] the in-order sequence. So can you also say that in-order is used to identify, pre-order [01:25:26] or post-order is used to identify the root and in-order is used to identify the structure [01:25:33] of the tree yeah yeah that is a good point okay okay yes yes yep so just confirming the last part [01:25:44] which you just answer to somebody i think so uh 15 and 29 that is answer said if you can give a [01:25:50] light on that once again that why the answer is not 15 why the answer is 29 or this 29 because [01:25:58] the null the null value now the zero zero or cross cross anything should we also be stored [01:26:02] into the memory indicating that the last point. So, if you store all those then it becomes 29, [01:26:08] if you do not store then it becomes 50. But usually when in terms of memory we also hold [01:26:12] that information that what is the last part, what is null or something else we store. So, [01:26:18] that will be explicitly mentioned in the question you have to consider the null pointer [01:26:22] or not while determining the number of space required by the tree. [01:26:25] so but until uh you have uh previous iterations information then uh you can actually store that [01:26:34] null pointer right that is a counter where you just save across so in this case if i just say [01:26:39] that is 77 after 45 77 which is where we are not going towards the left right yeah are we storing [01:26:47] the counter here for this particular edge uh is it the same that we are trying to say here [01:26:52] uh so uh that uh so basically this these implementation is done from the stack [01:27:00] hitting so from the stack uh the you can do a delay operation or i'm not if i'm not correctly [01:27:07] getting it so can you repeat so yeah if i just say the same way you said it the null pointer uh [01:27:14] understanding should be there with it so the 77 should also uh also have a left right which is [01:27:19] like the priority so now it's empty yeah so it's a null pointer so beginning with this if i just do [01:27:28] an implementation uh side of the thought that i should be maintaining a counter where the null [01:27:33] is happening for this left as well and then only i should be progressing to the next movement or [01:27:40] how the null pointer calculation will be happening okay so so when we go for a pre-order any odd [01:27:47] of the traversal from here null point so that will also consider but that will not be [01:27:52] dumped into the list main list that is there then how if this is not available in the main [01:27:59] list sir then how we can just assert that this was begin as a part of null null pointer [01:28:07] actually what happened we are not into the implementation when you go for the implementation [01:28:12] we store the information about both the child left child and right child left child is null [01:28:16] so that information is i mean yeah i mean we skipped the implementation also i mean in terms [01:28:22] of theoretical that we just talked about so if the three right which is uh written in the form of uh [01:28:28] list is in the right side of you after 30 the six is basically null right now if you see this [01:28:34] so the same thing you you you presented on the on the graph too that is on the tree travels the [01:28:39] graph yeah now if i have to find that which has been the null pointer uh and there the concept [01:28:45] can work across the extra spaces how we can just assert that this has been the extra space i'm [01:28:50] seeing the mathematical terms so that okay no because we have did not keep in sequential [01:28:55] representation we were following k 2k 2k plus one and so on so that's where this tree is created [01:29:00] okay and then if you are not getting any node at a specific place we are just leaving it empty or [01:29:07] saying it is a null pointer so okay should this okay okay okay uh understood but uh [01:29:18] i mean it's all sorry for my my it's still not clear already ended now so you can take your time [01:29:24] and maybe i'm not getting the what what you are trying to ask if you if you can explain this uh [01:29:29] if you can explain this tree once again if that is okay sir if that is okay okay fine fine so let me [01:29:37] This was the representation. So, what I did, I just follow k, 2k, 2k plus 1 strategy. So, [01:29:45] 1, 2, 3, fourth location is this, fifth location is this and 6 there was no node available. And [01:29:52] what it say that the 77 right left field is null, but right field is having a pointer. [01:29:58] So, what I will do, I will just skip it and on the right I will store 90 that is seventh location. [01:30:03] then eighth if you see for 11 is also same thing it's left field is null there is info part and [01:30:10] there is the address pointer so again eighth location is empty 15 is store on 9 25 is store on [01:30:16] 10 then on 11 there is again empty then on 12th and 13 empty okay then 14 location is built then [01:30:24] 15th is uh you can say empty and so on so this is how we are storing the tree so so we say in terms [01:30:33] of mcqs in terms of mcqs or questions or quizzes i mean in the any type of uh current exam this [01:30:40] part of right side of the tree would be given to us that uh this has the six as a like a null [01:30:48] pointer eight as a null pointer eleven and twelve yeah yeah that information will be given oh because [01:30:56] if the entire diagram is given then it is obviously easy for you if diagram is given [01:31:01] then both child information will be popular so that's where i'm just a bit confused like how [01:31:08] we will just assert if the tree is not available on the msecure itself no no no so that that will [01:31:13] be there so how you anyone can do this yeah thank you thank you so much thank you so much [01:31:23] okay so we are good to close i get more yeah yes thank you thank you thank you thank you for your [01:31:28] support