 So what if we took that same Tree that we had and I did make a little bit of a change I added a 1 to both the 7 and 8 because what if I rear back and I give you another insertion With another insert 7 so normal binary search tree rules apply. I see that I'm greater than 5 I'm less than 17. I'm greater than 6 and so that 7 would come in and Be applied here to the right child of 6 once again every node that has been Adjusted since we are in AVL trees. We have to Refactor their balance factors so 7 being a newly added in leaf node is going to have a zero because I can't go any further 6 is going to have in this case a 1 because its right node is heavier than its non-existent left node 8 since it happens to be 18 since it happens to be Here we'll go ahead and add it in since we're going to need to do a math medical calculation with it later 17 ah, so 17 we see that on my right side. I can go one node and on my left side. I can go two nodes So we see that it is that node is a little left heavy, but it's not terrible But this 5 you see 5 can go to the right Sorry the left once but to the right. I have the ability to go one two Three nodes what whichever node is the or whichever path is the largest my depth? If you will is where I would put this Now the reason why we kind of see this and it's a negative 2 The issue we have going on here is if I Notice I don't have sort of a parent going on here. I don't have a Z To work off of in my try node restructuring But I can't do a left rotation either you see if I were to do a left rotation just to sort of you can Do it on your own as a little practice If I were to do that left rotation, I would still see sort of my five. I'd get my six seven 1718 I'd see this structure right here and this is wrong wrong Because if you'd rebalanced out the the chart if you calculated out the tree you'd notice that 17 our root node would now just have a 2 as its balance factor So we did nothing to solve that so what can we do? Well once again since a Simple rotation does not work since a simple rotation does Not work We can change to the trinode Restructuring now in this case. I don't have a seven. I don't sorry a Z to work off of here. However If I were to view this structure right here since this is kind of where that seven was coming from I See that I can Sort of still make the same application apply I see that I happen to have my my parent node where it was super heavy I see been happened to have a another node that will call it sort of our normal parent node our Simple grandparent node and some other node Now in our case. We do the exact same thing. We've seen in the past. We need to map out in our case. What our a B and C Let me put those a little cleaner C We need to map out which one of our x y and z nodes is A B and C again. We follow in order proceedings in order means We would do left self right And so as we see here, I would see that my left child. I don't access it for this I know that seems odd. You're like, oh, no, that needs to be my a No, we're not caring about that. We're only dealing with these Three nodes right here. If you do this No, so I see that seven or sorry Z. I keep seeing that as a Let me fix that a little bit Z. There we go I see that my Z is going to be my a and then just like we've seen in our previous video We don't go directly to why because we have to go from self then we go to all our right children So when I get to 17 I deal with my left children first That's where that x comes into play and then my y is the remaining node Once again, if we're dealing with this restructuring node B is going to become the new parent a is going to get T1 and T2 and then C is going to get t3 and T4 So in this case, I'm going to move over just a hair in this case We see that by doing a Trinode restructure We are still going to make our B, which is in our case our x Our y and our z we're going to make our x the new Root node in our case. We're going to make y our right child We're going to make our z our left child And so now we get to look at where those t1s t2s t3s and t4s are so again the t1 is The left node of whatever our original z was so five is going to get the two Now what does five get well five is going to get either the t2 of x Or the t3 of x or the t4 of y in our case since we're on the left side It's going to get t2 t2 So in that case it gets nothing Now we go over to our Y and we see that y is going to get my t3 and my t4 So it gets the t3 as its left node and it gets the t4 as its Right node Since we made our rotation we can make a balance check to see that everything's fine. So As we've done in the past our leaf nodes. We know can't go any further. So they all get zeros Both five and seventeen can only go down one node each now our five happens to be left heavy and our 17 happens to be balanced and Finally our six it can go to on the right one two or one two and it can go to on the left one two And so we see that now we have a balanced tree