Now, in the previous video, we have learned to lift this condition and they have created a rotation
algorithm for that case.
In this video, we will learn left-to-right condition.
So let's say we have unnavigable three like this.
And right now it's past.
Let's say we want to insert this not a real tree over here.
So if you wanted to interface to this tree or here, as always, the first step is we are going to compare
it with the root.
So if it is this, then that is not we are continuing this subsidy.
If it is greater than the root, not, we are continuing right up to it.
So in this case, it's less than that or not.
You are continuing to the left subtree.
Now, one more time here you are comparing it with root.
Not so.
You see that it's less than the root.
Not so.
We are continuing to the left subtree.
So here again is less than the root node.
We are continuing to the left subtree until we reach the left.
So in the lymph node we see that 25 is greater than the lymph node, which is 20.
So this means that we will insert this not as a result of these over here.
Now, after inserting, we need to find out that if this three is barnstormer Soulsville Subform relief
not so.
We know that life is balanced so we don't have any problem then the parent of this difficult is 20.
So in this case, 20 is balanced because the difference between a of left and right subtree is one.
Now we are continuing to the next.
And also in the next note, we see that the difference between left and right substories hate is two.
So in this case, this number here is this past.
So after finding the response node, we need to find out the condition.
So the condition is we need to find the part that goes to the grandchild of this model over here.
So the grandchild of this TOTY is twenty five.
So the patch of this note is left, then right.
So here we identify that this is the right condition.
Now, after finding the condition, the question is which rotation we will use as a name of condition
such as.
So we have to do first list rotation, then we have to do right rotation.
So first we will do list rotation.
Then we will divide Rituxan.
So an important moment over here is the left rotation to the left side of this past now, which is 20
in our case.
So we are doing less rotation for that for the left side of this this past node.
So when we do the rotation, we move right up to the place of its parent and the parent is moved to
the left hand of this month, not over here.
So after left rotation, our Avio three becomes like this.
Now you see that after doing this rotation, this not over here is still this past because the difference
between left and right is wrong.
So to fix this problem, we have to do right to the station, as we explained in the previous lecture.
So here we are doing the right rotation for this this past month.
So when we do the right rotation, the parent node becomes the right side of its left child.
And this is what Area three looks like can be easily seen that this area over here is past, because
if you take the almost the head of left and right subtree is not more than one.
So it is the left right condition and hopefully everything clear about left right condition and and
how they are making it balanced.
Now, let's quickly recap what we have done over here.
Our initial version of April three was like this.
So here we identified that 30 over here.
Is this possible?
Then, as the name implies from this condition, first we need to less rotation, then we need to the
right of Tatian.
And you need to take into account that we are doing this rotation for the left side of these this path
here.
So if we do the rotation for this, these past nodes left, our Aviel three becomes like this.
So as you see after the left rotation, this becomes left that condition because the path to the the
grandchild is left left.
So here we know that in case of left left condition, we are doing right rotation.
So we have to do the right rotation for this displacement.
It comes down and the left child of this now becomes the parent of this not and left of this node stays
there.
So our April three becomes like this and it is balanced.
A three.
Now, let's see how the algorithm of left right foundation looks like.
So the algorithm is basically like this.
The first step is we are doing left rotation for this past, not left.
Then we are doing that rotation for this fast.
Now, let's see how this is working on an example.
So here, let's imagine that we have this past not like this.
It can be easily seen that it is left right condition.
Now, the first step here is we will do left rotation for left out of this displacement.
This means that this path is director station for this part.
So if we do the left rotation, the first step here is we are creating neural based on this right here.
So here we see that Russia is training for the new net will be twin.
Now, the second step is we are setting this balance nodes right up to the response node.
Right child left here.
So here we see that this is here and this balance will tries to revisit this past month right and left.
We see that for this right.
We don't have any left.
This means that this past node will be temporary because we are sitting this one two months.
So after setting the loss, that is, we are setting new left child to this displacement.
So all this quantum of is 10 and new is 20.
So after the rotation unit becomes like this, 20 becomes apparent and the response mode becomes a live
child of peace.
So after doing this rotation for the last child of these this possible, our displacement becomes like
this.
So here we can easily see that this is left left condition.
So in case of left this condition, we are doing the right rotation.
So here in the second step, we are doing right rotation.
So let's go right rotation for this displacement over here.
So as a first step from the algorithm, we are creating new route and setting it to left child was responsible
for the left side is the 20 and 20 has 10 as a left side.
So Europe becomes like this.
Then we are sitting this balance left child, which is now 20, put it this balance left and right from
the left just does not have Rachel.
So this means that we will see this balance left up to now.
So this becomes like this then we are setting new routes right up to this point.
So in this case, you see that you look like this looks like this.
So it does not have a.
So we will set 30 as a result of this movement.
So after doing this right rotation, our displacement becomes like this.
So here you can easily see that this is bounciness.
So after doing this calculation, we need to update the height of these box and root of this point,
because you see that from here to here, the head of these change.
Now, let's see.
Time and space complexity for this operation over here.
So the time and space complexity for left right conditions will be over because here in both metals,
you can easily see that we are just creating temporary not and changing the right and left files for
this and this company.
And we are returning this new world order here.
So these operations are here, does not require extra time for performing them.
And the space complex is for one, because here we are just creating a new record and returning it.
So this means that it will take over one space complex.
Now, with this, we have completed left-to-right condition.
So in this letter, we have learned what a different condition and can be identified and what can we
do left right condition to make.
So we have learned that first we are being left rotation for this past month left and then we are doing
the right rotation.
So hopefully everything is clear about this.
The right condition in the next lecture will learn.
Right.
Condition tune the next.