# DAA 11 Oct

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

---
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. So, in the last lecture, we have started the tree and we understand some basic concept key, what are the tree, parent, sibling, so we started tree and we understand what is binary tree, then we understand the complete binary tree, binary tree. And we also explored the basic terminologies and we also explored the representation in the memory, representation of tree in memory. So it could be done in two way, one was link representation and another one is sequential representation. So sequential representation was simply that one, k was the parent 2k, left child 2k plus 1, right child. This you have to apply it everywhere and you can get back the location of the, all the

nodes in the array. So yesterday we were discussing about link representation, then sequential representation. So link representation was primarily done with the help of bi-directional linked list. bi-directional linked list where the middle part hold the info and if you remember in the data structure this is referred as previous and this is referred as next so previous hold the address of left child and next hold the address of right child and first node obviously will be a specialized node or that will be the initial node you can see and that has a special pointer that is called start pointer and from here if we start. So this is the info, this left child, right child, again, this is info left child, right child and here there is no left and right child. So this is the leaf node. Again, f is the leaf node, no left and right child and here this e node is having one left child. So right one is crossed or it is having a that is called as the null pointer.

So, these are the, this is null pointer, this is null pointer, this is null pointer and so on. So, this then we have seen this as well, how the things are represented in memory, so what we found, the first address is stored in the root or sometime somewhere it is also called as the start. So, I am starting from here and I had an information about left and right child and if you go to the 10th, so we obtain B that is a left child and again its left and right child are stored on different location when we go to the 18. So, we found D that is a right child of B and both the child's are, a left child of the B and both the child's are in the 0 indicating the null point. we also seen there is a avail list that indicates that indicates the starting pointer for the empty location in the memory then yesterday someone was asking why not starting with 4 why starting with 8 so there is a reason that whenever any operation

release some empty space and this could be only done in case of linked list not in case of array linked list it is added on the top of it is added on the top of the available list it is added on the top of the available list so that's why so maybe initially we have all empty but as different operation continues we have given dedicated memory but at last the deletion was happened on the 8. So, this 8 also indicate location 8 also indicate the last deletion was happen was happen at location 8. So, this is a simple thing when any operation release some memory. So, its empty space is added to the avail list and why we are having 8 because 8 may be the location where this release an operation was happened. Then the next representation is called as the sequential representation. So, same phenomenon we will all do. So, root will be stored at tree 1, first location, first location. So, I am following the

index 1, if you follow index 0, so you have to change accordingly, just reduce. So, this tree will be stored at 0, left will be stored as 2 k minus 1, right will be stored as 2 k plus 2 k. only okay so then null is used to indicate the empty tree so that already we have discussed if there is empty space let us say i am storing the tree in a array okay and if there is a empty space so that will be inefficient utilization of the memory so whenever your tree is complete or near to complete we will prefer sequential representation because of its easier implementation but when your tree is you can say sparse or not enough nodes, but having enough height. So, then we will choose the length representation. So, this is how if we want to represent this tree in the memory. So, this location is 1, this is 2k that is 2, 2k plus 1, 3. Now for this, 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

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 what we found this space is empty this space is empty this is empty this is empty this is empty So, so we required 14 location in an array even the array has 9 nodes and even if you consider all the child's of the corresponding node, in fact, if we include null entries for the successor of the terminal node, we will actually need 29 space. But we were only engaging how much, only 9 entries, engaging only 9 entries. So specifically the sequential representation of the tree with depth d will require 2 to the power d element. This much elements need to be stored. And if your tree is here, this tree is not a complete binary tree or even you can say that it is also not partially. So this type of things you will and here if you see we are just only discussing about the 14 entries and if let us say we are discussing about millions of entities.

So, lags of space will be remain unoccupied because of the sparseness nature of the tree. Now, so next part that is traversing in the binary. So we understand the representation, either it could be in the form of link or in the form of sequential array with the convention of 2k, 2k, 2k plus 1 and dot dot so on. Now, what is traversing? So traversing is a mechanism of visiting all the nodes exactly once. So there is difference between traversing and search. So traversing or traversal is the mechanism visiting all the nodes exactly once. So we have to visit all the nodes exactly one time. So that is called as the traversal. And what is searching? is the operation of identifying a dedicated key. So, you can say that traversal is a extended form of searching but better to keep it separate. So, traversal means that we are visiting all the location and identifying what is stored and what is not stored. Just one key, I want to print all

the entries of the tree then I will use the traversal. And what is searching? Searching is the terminal of identifying a specified key. So that is called as the searching. Now traversal, so there are three types of traversals in tree that could be possible that is pre-order, in-order and post-order. So, pre-order. So, usually if you see the tree, so what it should be? There should be left child, there should be right child and there should be root. So, this is called as the pre-order. I am using what? R is root, root, this symbol just root, root, traverse means that whom I will visit. So, on each node you have to take this decision, whether you are following pre-order, in order or post-order. So, R will indicate root, L is left and RH I am saying is at right. So, when it is pre-order then what I will do? I will follow root left right, pre means that root should come. So, This ordering will depend upon the placement of the route, pre means route should come

first, in means route should come after left and post route should come after left and right. So that is the main mechanism that we adopt, pre-order means that process the route, traverse the left in the predecessor and traverse the right in the predecessor. That is root left right this decision we have to take every time that is called as the pre-order. Then in case of in order traverse the left child traverse root and traverse right child that is left root right this is called as the left root right and pre-order is called as the root left right and to remember what is the thing pre means root should be pre appearing in means root should appear in between and post means root should appear after left and right so first i will process left then right then root so this is called as the left right so this is called traversal or tracking so let us see this example a b c d e now here Here I am following what? I am saying as determine pre-order. So pre-order is what? That is root

left right. So on the A, who is the root? A because we will start with the root root. Then I will visit what? Root left. And if you see on the B, B is as well as a root. Then Then I will go to the root left right, now left child is D and right child is E. When this left is over then we will go to the this part, then what we will want C F. So, this will becomes the pre-order, pre-order means that root left right. Now if you want to determine in order, so in order says first left, first left. So, the in order first one will be what? one will be what? D, because it should be what? Left root right, then D, then root is B, then what we will cover? E, this subtrees cover, then we will go to A, then there is no left. So, C will be covered and F will be covered in the last. So, this will become the in order that is left root right. Now, if you want to determine the post order, what What is post order? Left right root, left left, then E, then B, then F, then C, then A.

So this becomes the post order. So what the significance we found that in pre-order first node will be always the tree, first node will be always the root and in post order last node will always the root and in order the root will appear in between the left and right chain. So, root is appearing in between the left and right chain. So, this is the thing. So, let us do some more examples to understand the traversal in the tree. Then we will try to construct back a tree from a given in order post order notations. So for getting back the tree, we need, there are two possibilities, pre plus in or post plus in. So if we have these information, then we can retrieve the tree as well. Or let us say, I want to do the sequential representation here. So I will just maintain the pre-order and in order in an array and we can fetch back the tree without following the notations of what k, 2k, 2k plus 1. Simply what I will do,

I will determine pre-order, I will determine in order and push them into two different array. Now, whenever the tree we want to regenerate, then using these two, we can get back the tree. So, that we will see with an example, but let us do some more example for pre-order, in order and post order okay so everyone just check whether this pre-order in order and post order what i have written is correct or not okay so giving you five minute just do it then i will solve this problem and one or two problem i will also do okay so everyone just do this uh yes mohit so you raise the hand yes you are asking for the third okay okay so i will i will make you moderate thank you thank you man just give me a minute okay now you can provide mic access to other as well okay so i will take queries okay but uh let me solve this problem in chat someone has also solved this okay good so uh let me do this okay someone has solved

and i will take queries okay after some time now talking about this whether these are correct or not. So, first one is pre-order. Let us do it. So, pre-order says root left right. So, every decision we have to take. So, from here we will start. So, root then we will go to the left. So, b is also the root of this subtree. So, I am covering root then root left right. Now, here we will only have root. So, d now in this part we will go. So, again e is the root and f. How left is the, so root left then right, c is also the root, then left is 1g, then h is root, then j is root, then l is root, then k. So, that is every time what I am following, root, left, right, root, left, right, root, left, right. Everywhere just think about just 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, that is correct. Now talking about the in order. In order is what? Left, root, right. So, here a,

no left, no D. Yes, this is the last sign in the left. So, I will start with the D, left, left root is B. Then I will come to E. So, I can consider E, but it is having the left side. So, left root right. So, F, E. Then we will go to the A. So, left is done, then we are going to the A, that is root. Then on the right here we come, so c, but c is having the left child, so left root right, so left is g, then left root c, then here we will go to the right, so right is h, so it is having what, left child j, left child l, so l, j, h, k, so this becomes the in order. 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. So, L, J, K, then H, then C. What we found? C is then, sorry, K, H, C, A. So, K, H, C,

A I am writing here. So, left. So, the basic thing is that whenever you obtain a tree, okay. So, what we will primarily check? We will primarily check, we will in case of in-order and post order go to extreme left. Go to extreme left and then take the decision or simple thing is that on all the nodes just do not forget about the tree. Consider only these three nodes and start thinking what is the property left root right that is in order. So here is left is b and c is, so left root right. So I will come to this node. Now whether I will consider this or not because now when we consider b then this subtree will be obtained. So left is d, there is no more child. So we will consider d and root is b, again consider e is another root but when we reach to the e then this is another subtree. So here we will consider f, e and another, there is null child. we will jump to the A. So, just consider trio and this trio consideration will continue when

when we reach to the label where there is no further child, then we will start writing it. In case of pre-order, pre-order says that it should be root left right. So, immediately you can consider the first node that you encounter. So, very simple example. So, if you consider the pre-order so that is root left right can i consider post order so it says left right root and in order is left root right so here it is okay so this is simply one more example if we can see now for pre-order will be a root then left that is also a root then left right. So, A, B, D, E and last one is the C, that is a pre-order. In order means, in order means that first go to the left extreme left, so that is D, in order is left root right, left in root and then right okay so this is in order so this in order pre-order and post order you can apply on different different nodes considering the try of left child right child and root okay similarly here if we want to determine the post order if you want to determine

the post order okay so what you can do that is left left then now we have left right root left then come to the right then root so here it is so that is a post order okay so what we have did if we want to store this six node we can use pre-order and in order or pre-order and in order and then we will understand how we can retrieve back a tree. So how we can retrieve the tree back using the combination of post order, in order, post order, pre order, in order. So multiple examples I have put. So here it is marked wrong. So why this is wrong? Let us check this one. just a minute and so now if we want to check the pre-order thing okay so let us see why this pre-order says that root of course one will come then left that is two that is also a root then left that is four that is also a root then seven that is also a root left is not there then we will consider right then we will come back just give me a minute

sorry for the delay okay number of interruptions are appearing today so let us continue okay okay so the next was this one we were discussing about the determination of the pre-order why it is wrong I have mentioned. So, we what we found that it is first we have to visit the route. So, that is one then next one is the left that is also the route then 2 then 4 then 7 then 9 then we will go to the 5 then afterwards we have a right. So, that is first because it is pre-order, so root, so this is 3, 6 and 8. So, if you compare both 1, 2, 4, 7, so it was correct. So, just I have intensely mark a line over it. Now, a question arises if we have pre-order and post-order, so how we can generate the tree. So, let us see some simple example, even we can start with this one. Now we have, we have pre-order and post-order. Just I will write down the content. So, let us reconstruct back the tree from the combination of either pre-order or post-order

or post order and pre-order. Now, we have pre-order that is 1, 2, 4, 7, 9, 5, 3, 6, 8 and in order because in order is mandatory. Either you are using post order or pre-order but you should have in order that is 7, 9, 4, 2, 5, 1, 3, 6, 8. So, pre-order we know that first node is always the root node and from the in order we will identify it will hold left child and right child. So, here we have one, so left child are 7, 9, 4, 2, 5 and on On the right we will have 3, 6, 8, then this node is done, now we will shift to the second root. So second root is here and if you see second root, so left is this one and right is this one. So next step will be 1 and second root is 2 and here we have left that is 7, 9, 4 and On the right we have 5 and this will be as it is 3, 6, 8. Then the next root if you see is 4. So 4 is where? Here and 4 left are 7 and 9 and there is no right child because already these nodes are

visited. So 1, 2, 3, 6, 8 and here we are having 4, 7, 9 and this one is 5. Then the next root will be 7. So, among these two, 7 is the root, there is no left child but there is the right child that is 9. So, what we will get? 7 will be this and 9 will be its right child. 9 will be its right child. So, now then we will identify next root that is 9. So, 9 will come because if you see here both the nodes are already traverse. So, 9 will remain intact. Now, the next root is 5. So 5 here there is if you see 5 both the things are already traversed so nothing to worry. Now the next node is 3. So 3 will be here and 6 and 8 are what? Right child. So 6 and 8 will appear here. Then after 3 there will be the node 6. So 6 will be there and 8 will be the right child. If you go to that already the nodes are traversed and we will get back the structure. 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.

So, we are getting back the original tree by using the, these two things. Or what we can do, we can in two arrays, we can store in order and pre-order. And using them, we can retrieve back the tree. So, this is, this traversal is also efficient or essential when the tree is very sparse. So, we can use two arrays for storing them and its storage is not likewise k2k, 2k plus 1. You can simply store what? The same order, root left right or it is pre-order then root left right. If it is in order then left right root, we can store in two different array and get back the tree. So, let us reconstruct this tree using post order and in order. So, post order, post order is 974. 5, 2, 8, 6, 3, 1 and in order, in order is 7, 9, 4, 2, 5, 1, 3, 6, 8. Okay, slow down, we are constructing the tree from the post order and in order. So, we know that in post order, the first node lie in the last or the root node lie the last one then if you see one so left child this one right child this one okay seven nine

four two five three six eight then next node is three okay so next node is root is three so if you see three so here three left already covered right is there so one seven nine four 2, 5 and here we have 3. Then if you see second node is 6, second root is 6 after 3, 6, then 8, then we are having 2. So, now this will be divided. So, what we will get? 1, 3, 6, 8 and here we will get 2 and if you see 2 position is 7, 9, 4 and on this it is 5. Further we will see the next root that is 5. So, if you see 5 both ends are covered then we will see this next node that is 4. So, what will happen? 1, 2, 3 and 4. So, these are the left child 7 and nine seven and nine are the left child and four is here okay then next node and so on so what we are seeing that when we are using pre-order and in order combination we are generating the tree from left to right and when we are using post order we are generating the tree from the

right to left okay now i will take your queries then we will start the binary search tree the next think that okay i have enabled your mic okay okay yes because anyone can start asking the questions yeah i have enabled your mic uh sir can you go back to the last uh example sir just to control this one yeah yeah uh can you just let us know how this uh turn that happened from one to five and then i mean from our start of the route like when you said right we decide the new road itself on the two that is the new one how it begins so yeah so i have just start picking the roots from the post order because we know that the last node will always the root so one then next root is three so see the position of three in order so it says that these are on the left and these are on the right but one already track so we will not consider the left child we will only consider the right chain if i encounter a node that is already traverse okay or that is

already covered so i will stop movement in that direction so for three i will not go to the one i will just only consider the six and eight uh okay so in case uh just to confirm sir in case i mean how to confirm this that the tree which is formed right after this has got the relative information which can cover maximum of the tree uh relevance i mean in this way uh is there is any way to understand or calculate as you will get same tree you will get exactly same tree what we have uh earlier from which this post order and in order are calculated so there will be no difference okay okay okay so so uh if you are getting same tree so there will be no loss of information or anything you are retrieving back it okay so in case the equivalence is there so there is no lost information yeah yeah okay if you are following same process and if you have exact information about pre-order in order then you will retain back that uh but in case of this

sir that is pre-order the right most which is like one three six eight it is a invalid rewrite it's a skewed one the skewed one no worries now because here we are not talking about memory efficiency here we are just storing the element in the one two three four five six seven eight nine locations not following k2k and other stuff but still we are getting back the tree so in terms of memory efficiency we have very much sparsity so you can use two array and store these information and retrieve by the tree whenever required okay i mean why i'm just putting that question again because yesterday we told about that uh if the tree is having a left function right which is like you have to write movement that is a valid tree and this one this is a pre-order which is the right most seems to have a right life you can say right life which is on the one three six eight as a till root sorry as a till leaf actually so was it a was it an invalid tree or it's a valid

tree itself no so this is so this tree is valid so not if this tree is not complete tree you can say but this is valid okay this is valid because here it is not already although yes i just got your point okay let's say this is a skewed tree this is a skewed tree but this is tree this is skewed toward right and left and there is imbalance in there are number of imbalances here but of course this it is a treat so it is not right or wrong tree it is a balanced tree or unbalanced tree so here the complexity of searching may reach toward order of n and if it is perfectly balanced so it will reach to a log of n i think so balanced tree and unbalanced tree not wrong tree and right tree i mean maybe the terminology i'm kind of hindering in there but i'm just tired of confirming whether because yesterday's concept is kind of con in making a collide here and that's where just sort of confirming sir okay okay thank you no

no no so still if you are just because maybe this doubt is uh coming yeah i mean yesterday's only uh that's the discussion was there where you have it is as a left uh less left distribution right that it goes to a uh correct combination okay correct generation of the tree itself but right now we see the right one which is already falling to one three eight which means are we following in a correct tree tree formation itself or it's a skewed or it's invalid tree so then that's where i'm just so yeah okay so invalid uh you cannot say you can say skewed so if i'm adding node here and here so this is right skewed and on that yesterday i was saying it should be toward the left when it is a last node having one check so that was complete tree so i'm not talking about completely we are only dealing with binary a complete or partially complete tree sir that you explained yeah complete or partially complete but this tree is sparse if

you can see there is no node here no node here no node here no node here no node here so this is a sparse so this is but not a complete or partially complete tree so still it will be valid yeah yeah the tree will be valid but not complete and so it will be not memory efficient to store this in the array but this is trick yeah and what kind of use cases we used to have for this i mean is it the same uh ram use case that we talked about that uh efficiently so that uh that use case we will talk about but what will happen if we need extra space for storing the information where the value is already not stored so likewise in the same on the blank space yeah so blank spaces will be there if you try to push into the memory okay okay so oh sorry for taking a few minutes no no worries maybe others are having same doubt now that's why i'm happy to yeah hello sir good morning good morning sir i have a doubt regarding this tree or data structure

as you mentioned that it's a non-linear data structure but then we see that we are storing the data points in the linear data structure like array or linked linked list so i mean what's the benefit we will get if we are still storing. So your memory is simply the from 1 to 1 0 2 3 as I was taking the earlier example. So it is your memory is you can say best represent the array hitting. If an array as you store the element similarly your memory is also available but these data structures are the logical organization. So this is not physical organization. okay this is a logical organization where we bound certain set of rules so that we can efficiently access and do the insertion deletion and traversal faster so every time when we say data structure it does not mean that we are physically doing something it is a logical organization of the memory to enhance the speed of insertion deletion traversal and searching okay so under the hood

it's all array yeah yeah so it is of course will be form of array or it will be form of linked list and no third form so stack is one logical arrangement q is another logical arrangement tree is another graph is another disjoint set number of data structures we have but all are the logical arrangement because your physical memory is zero to one twenty three there is no jumping and others they are available to you and sir i have another question when we say sparse tree so so it means for any given sub tree if there is a null pointer or if we don't have any child in that sub tree then we will call it as sparse means that it is you can say a positive completely where the number of nodes or or all the nodes are not having both left and right child or most of the nodes are having only one child so that that kind of situation it is okay so if there is no child that means we have the null pointer as we discussed yesterday yes yes yes okay and sir i have another

question from yesterday topic when you were explaining about the binary tree representation so in in linked representation you mentioned that we have three variables if i say it correctly like info root and avail yeah so these three variables needs to be initialized yeah yeah any problem statement so we have to have some root and avail and then we can start and form the representation so avails it's a you can say complementary you can skip avail so you have just root information okay and then you can start and and afterwards you will get left child right child info part is the information content okay and and others are the pointer for the left address right address and so on okay okay okay sir thank you yeah i think sir kumar pande good morning sir good morning sir basically uh as i these are the things of like traversal right pre-post and in order yeah so basically sir uh my doubt is like pre-order which is fine basically

we visit the root node then left then right but in post and in order we are visiting like for the post order first it is right then root and then uh left that is for post order is uh left right root yeah so basically sir how we can do the traversal without visiting the root node that my question because uh if we want to traverse we have to start from the root right because we have the only this that pointer to be started with so i'm not getting that how can we start with the leftmost without visiting the root okay so when i visit the root and i'm saying i'm using post order okay so immediately without uh let's say i had a operation of printing the root value okay just print the info part so i will not engage the print function unless there is a child on the left side or right side so i will just go down down down to the left most part if there is no child then i will initiate the print statement and then i will write print d

or print f and if it is pre-order then what i will do i will go to the root first print it then check the left and right child then print them then check left and right child then print them and so on getting okay okay so basically means it is like we visit the root node but we don't look into the info part of it unless what type of criteria we are following okay so basically then it is i think the violating the statement that you have given that uh every should every node should be visited exactly once so basically if we do post order then we are visiting like twice because once we visit then we don't see it and then again we come and see to print it out yes yes yes yes yes so basically in post order and in order there will be just redirection as per the policy unless we are meeting the policy then we will do the print statement if this is just example yeah yeah so so basically it's like the violation of the

definition that is what i'm trying to get because it is like exactly once so in post and in order we are not doing exactly once it is like exactly more than once yeah so i'm totally getting you so uh let's say um i'm taking a simple example if i visit to your house okay and i just ask where the look the location of uh monies or something is located you just redirected okay i don't bother about you or perform any operation or even see you just get a redirection that you should not go there you should go to the left child rather than going directly to the root so that redirection is happening actually when you go for the implementation it is stacked based all these post order period are stacked based so root and left child other things are pushed down into the stack and we are processing the top element always so top element will be the left side okay so basically my concern is not not to that my concern was just only with

the statement so it it should not be like exactly once right because uh traversing or visiting means that we we are performing the print operation you can say not the redirection decision okay not the redirection decision yeah okay thank you sir that was that was like it was a bit confusing no no good good question it was yeah hello hello good morning my first question is the page number seven it has a calculation to find the the level that log n plus one can you just go to that page seven this one seven seven it is twelve yeah go back back seven is not there seven number slide i will open okay okay i'll just tell you that dn is something like log n plus one okay but in this case you see this one this n right n will be the number of elements so number of elements for complete binary tree will be always odd numbers yeah right so that case if i to take the log n plus one right it is something like n plus one together and then take a log on on that because

because if i see that level one let us see two to the power uh zero so that's right that is one yeah if i take two to the power uh one right that is two plus one that's three yeah yeah right but here thus the given is something like log two n plus one not the bracket okay i guess in yesterday slide it was so uh yeah we'll we'll check also there might be some uh bracket issue or something i have yeah okay so yeah yeah so the second one is regarding the depth yeah depth is similarly sir you have given two to the power d plus one but the question is the number of elements will be always in odd numbers so if you see two bit but d plus one it will be always an even number so is it okay or so see so this much memory you will engaged okay although you will not occupy so you you may occupy some odd ones so one or two may be used by later program okay so that is this is a number of node in the depth d there is a simple representation here okay and third question is

regarding that evil let's see if one element does not have any parents right yeah yeah so that case evil but because in real life scenario in database like your like parents or indexes right we never use anywhere there is no parent sir is there any real life scenario wherever we use the element having no parent but we travels to that element no so that is not possible because linking is should be there now so if there is so in database if you go with the stack implementation on anywhere if there is no pointer to the parent okay so that will be you can say that node is automatically removed because we cannot access that there is no access path node will be killed exactly if i move the manager means it is completely moves like subsequent employees okay yes yes okay sir thank you yeah good morning good morning sir good morning sir what do you know how to determine the size of the area where we are storing the tree so

that that is this formula now two to the power d plus one that was given this much number of element we need so this much storage is needed okay okay yeah so how it is 20 answer here so uh 29 means that if we are considering all the child and other stuff okay okay then one okay so but if you go with the formula so then all the null pointers will be stored and everything will be stored then only we can take a decision over so d is the number of node here this is the the depth depth okay yeah thank you sir i have another question uh so basically in the linked list when we delete an intermediate node we basically join the previous node with the next node yes yes skipping the deleted node yeah but what will happen in case of tree if we delete let's say the intermediate sub tree so the underneath whatever nodes we had that that will become orphan so no no so that is not so we will see the deletion so whenever let's say I want to delete a root node so it's left child

or right child will take over its position and the pointers will be adjusted accordingly so we'll see in later on when we discuss binary such tree and other tree so there are different mechanism of deletion it is not simply remove it we have to replace it by in order successor pre-order pre-order successor or anything number of things we have to do then only we can go ahead but in a way we are storing the tree into linked list format right so let's say i want to delete b in this example i want to delete b so in while doing the deletion in tree we will not immediately remove b we will remove b with its immediate uh in order previous successor and then we will remove it so in tree that the relation is not there it is replacement so we will then we will be removed so there will be no change in the links yeah okay fine so you will be covering the deletion the deletion is important insertion deletion every tree you will find how insertion and deletions are done okay thank you

i'm having also one doubt yeah yeah when say slides seven where you have shown the table that avail basically right it's regarding deletion yes regarding deletion only let's say eight that somebody has asked questions now only if there is no parent uh i mean id let's say eight wherever you have written eight there's nothing mentioned as a parent right yeah yeah then how we can mention the left whatever mention nine okay i mean if there is no parent then how the child will be there no so this is just a linking so yeah the avail pointer or the empty space are linked in a one-way list okay so there is info part info part is null and the pointer to the next so this is an aggregated of all the empty space in the memory so whenever memory is needed we will delete from the top give give it to it when there is deletion or available memory we will add it on the top so insertion and deletion will be order of one so that is thing is i'm getting i had just

information about how much available space is there and all are linked if i want to use 10 space so it will provide you 10 locations not consecutive location here and there but they are linked together if it is not linked then there is then we have to explicitly search all the empty spaces and then we will find some of them so that's why this linking is established info part null but there is a pointer so the meaning nine is that there is another one where the empty space is there and whatever is mentioned with the nine the top one is eight there is no info part then the next available space is available at nine next available space is available at four next is at 14 then 15 then 16 and so on but sir we have mentioned left this one that's the basic doubt i mean no no so that is not this is a single address pointer we will always hold okay actually what happened we are directly covering the algorithm in data structure the um the avail

thing is discussed in detail so it is always a unidirectional not bi-directional linked list so i mean this we have written as a part of this list but it is is but but but it is explicitly it is something this is separate separate purpose yeah yeah hello sir yes yes yeah sir uh actually my uh doubt is regarding this as well only so you just say that um it's uh deleting from the uh top and if there is any memory uh space empty then it is coming to the top yes suppose i have i have uh four memory indexes empty right so um then after that suppose that fourth place of memory is uh free so fourth will be used fast and fourth will be uh if if forth coming after those staffs then forth will be used first right yes yes yes yes so it's like uh creating like a stack means yes yes yes behind the avail there is a stack always yes okay and sir one more question that regarding b complete tree that uh for the previous class

so yeah could you please go to the go to the last pre-order post-order in order uh three just go to the last slide this this this last last slide last one last one so yeah this is the last name uh okay then so uh suppose you ask for a uh creating a complete b tree so you told that um we we skip that right one. And if there is any leaf that is on the empty one, any leaf, so we need to put it to the left. So here sir, if some leaf is there at upward, like it is 44 after the 33. So, if I create a complete B tree, then 44 will be that left one, means we need to shift all the nodes to the left side, means suppose that there is 10 and 12. So I am just saying, if a complete binary tree is a definition of something and here this structure is already present, we are not going to modify any structure of the tree, we are just doing a traversal, pre-order, post-order, in-order. We are not modifying the structure. This tree is there, you have to accept and you have to apply all those three

things. And if I want to create a… So, suppose there is a question like this is the structure. If you create a complete B tree, then after traversal what will be there? Okay. So, if complete B tree is there, we need to make it a complete B tree and then traverse for the pre-order. Suppose there is question like this okay so let me let me show you an example because the already existing tree you cannot modify anything okay so i will create a complete tree so one three then four will go here then seven then eight okay then nine then ten then eleven will go here 12 will go here 14 will go here and 15 and let us say 16 is also existing 16 will go okay so now this is complete binary agree now if i want to do a pre-order of this one so it is one then three then seven then eleven twelve then eight fourteen fifteen four nine sixteen and ten okay so this will be the pre-order Yeah, but this tree is not partially complete Bt.

This is complete Bt tree. This is complete Bt tree. Yes. So, you told yesterday there something the partial tree also. So, you need to modify that. Partial means that, let's say I have just removed this branch. Remove this branch and make the 16 to the right one. Yeah, 16 here. Yes, and remove this one. yeah so uh if we need to traverse and uh with the complete means if we create a complete b tree from from this partial tree then we need to shift that 16 to the no no no no so converting an existing tree into complete trees is uh not suggested because there then you have to do release and insert some number of operation you have to perform directly it cannot be shipped okay okay okay okay thank you sir good morning sir good morning sir I will create first node one but who are left and right check this information will be given from the in order so that's why these two combination is needed okay thank you sir sir one more doubt uh yes just uh just uh go to the slide

number 13 that is uh you write one uh item with t of 29 that part this one yeah yeah this one uh sir how there the tree is 29 it should be the 15 right means if it is if we come complete the tree okay complete the binary tree means it is actually required if we consider all the successors okay all the left and right child that are although empty but we are considering so it will take 29. Okay. So, if there is a question in MCQ like that, so how many that successors will be there? Okay. That will be explicitly mentioned that you have to consider the null pointer as well or not consider. If not consider, then 15 is the answer. If consider, then 29 will be the answer. Okay, sir. And one more question that is regarding the depth. So, for the depth, we only calculate the edges, okay? So, do you need to calculate that root also? Means here, we can consider the depth is 3, right? 1, 2, 3, yes. And edge can be represented what?

47, 77 edge, 77, 90 edge, and 90 and 15 edge. Okay, so that is the 3 edges. So, edges can be represented with the help of pair of vertices. yeah and so the depth so depth will be the three right uh so in the depth calculations do you need to uh calc means add the root root also means here uh three plus one or only three what will be the answer for the depth calculation sir what means for the depth calculations we need to include that root also only that ages only the ages or x the nodes accept the root except okay i guess we are good to close uh although this class was a little disturbed yes yes sir one more uh vikash anand then i'm just yeah uh sir so to recreate the binary tree from this in-order, post-order, pre-order, we need either in post or in addition with the in-order sequence. So can you also say that in-order is used to identify, pre-order or post-order is used to identify the root and in-order is used to identify the structure

of the tree yeah yeah that is a good point okay okay yes yes yep so just confirming the last part which you just answer to somebody i think so uh 15 and 29 that is answer said if you can give a light on that once again that why the answer is not 15 why the answer is 29 or this 29 because the null the null value now the zero zero or cross cross anything should we also be stored into the memory indicating that the last point. So, if you store all those then it becomes 29, if you do not store then it becomes 50. But usually when in terms of memory we also hold that information that what is the last part, what is null or something else we store. So, that will be explicitly mentioned in the question you have to consider the null pointer or not while determining the number of space required by the tree. so but until uh you have uh previous iterations information then uh you can actually store that null pointer right that is a counter where you just save across so in this case if i just say

that is 77 after 45 77 which is where we are not going towards the left right yeah are we storing the counter here for this particular edge uh is it the same that we are trying to say here uh so uh that uh so basically this these implementation is done from the stack hitting so from the stack uh the you can do a delay operation or i'm not if i'm not correctly getting it so can you repeat so yeah if i just say the same way you said it the null pointer uh understanding should be there with it so the 77 should also uh also have a left right which is like the priority so now it's empty yeah so it's a null pointer so beginning with this if i just do an implementation uh side of the thought that i should be maintaining a counter where the null is happening for this left as well and then only i should be progressing to the next movement or how the null pointer calculation will be happening okay so so when we go for a pre-order any odd

of the traversal from here null point so that will also consider but that will not be dumped into the list main list that is there then how if this is not available in the main list sir then how we can just assert that this was begin as a part of null null pointer actually what happened we are not into the implementation when you go for the implementation we store the information about both the child left child and right child left child is null so that information is i mean yeah i mean we skipped the implementation also i mean in terms of theoretical that we just talked about so if the three right which is uh written in the form of uh list is in the right side of you after 30 the six is basically null right now if you see this so the same thing you you you presented on the on the graph too that is on the tree travels the graph yeah now if i have to find that which has been the null pointer uh and there the concept

can work across the extra spaces how we can just assert that this has been the extra space i'm seeing the mathematical terms so that okay no because we have did not keep in sequential representation we were following k 2k 2k plus one and so on so that's where this tree is created okay and then if you are not getting any node at a specific place we are just leaving it empty or saying it is a null pointer so okay should this okay okay okay uh understood but uh i mean it's all sorry for my my it's still not clear already ended now so you can take your time and maybe i'm not getting the what what you are trying to ask if you if you can explain this uh if you can explain this tree once again if that is okay sir if that is okay okay fine fine so let me This was the representation. So, what I did, I just follow k, 2k, 2k plus 1 strategy. So, 1, 2, 3, fourth location is this, fifth location is this and 6 there was no node available. And

what it say that the 77 right left field is null, but right field is having a pointer. So, what I will do, I will just skip it and on the right I will store 90 that is seventh location. then eighth if you see for 11 is also same thing it's left field is null there is info part and there is the address pointer so again eighth location is empty 15 is store on 9 25 is store on 10 then on 11 there is again empty then on 12th and 13 empty okay then 14 location is built then 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 of mcqs in terms of mcqs or questions or quizzes i mean in the any type of uh current exam this part of right side of the tree would be given to us that uh this has the six as a like a null pointer eight as a null pointer eleven and twelve yeah yeah that information will be given oh because if the entire diagram is given then it is obviously easy for you if diagram is given

then both child information will be popular so that's where i'm just a bit confused like how we will just assert if the tree is not available on the msecure itself no no no so that that will be there so how you anyone can do this yeah thank you thank you so much thank you so much okay so we are good to close i get more yeah yes thank you thank you thank you thank you for your support

