Hi, everyone.
So today we are going to solve this question in work by military.
OK, so this is basically a binary tree and we have to invert this tree.
OK, so what is the meaning of inverting a binary tree?
So inverting means basically draw a line in the center line.
OK, now what will happen?
So basically three will come here and two will come here.
So first of all, one in two will be swept to entry, will be swept.
So three and two, then six will come here and five will come here.
So basically, this will become six.
This will be five.
And then similarly, four and seven will be stabbed.
OK, so seven will come here and four will come here.
OK, let's take one more example.
So we have to invert this binary.
First of all, let us draw the line.
OK, now what will happen.
So we will step two in seven.
OK, so this will become seven and the system.
Now we will swap three and six.
So six will come here.
Three will come here.
Now we will swap one and nine.
OK, so nine will come here and one will come here.
OK, so this is basically the inverted binary.
OK, this is invited by Nutri, so the input is basically this by the input will be this tree and we
have to return this inverted by Nutri.
OK, so I hope you understood the question.
Now let us know.
Let's discuss how we can solve this question.
OK, so this is a very simple question now how we can solve this question.
So let us consider root.
So in the root what we have.
So this is basically subtree, this is basically the right subtree.
So basically what we will do, we will swab the left subtree and we will swab the right separately and
then we will call the recursion on left subtree.
Then we will call the coalition on right subtree.
OK, very simple.
Let's Bridon, on this example.
OK, so I have four, then two, then seven.
Then one, three.
Six and nine.
So what we'll do, first of all, so this is left subtree and this is right.
So first of all, swipe left and right, Sabari, we have two separate left and right.
So it will look like this four, seven, six, nine.
Then I have basically two, then one and then three.
OK, so now this is the Route seven is the route.
So SREP so seven, this is the subtree and this is the right subtree.
Similarly for two, one is the left and three right sabari.
So we will swap.
We will swipe left and right.
OK, so let's six and nine.
OK, so nine will come here, it will become six.
Similarly, let's wrap the left subtree so it will become three and it will become one.
OK, so very simple.
We just have to step left and right subtree and we will call the N word function on the left and right
separately.
OK, so let's write the code and then you will be able to understand it in a better way.
OK.
So we have to return basically the root of the inverted banditry.
OK, so first of all, best case.
So basically if rotational.
Basically, two did not exist, so we can take leader dandled, there's no need to do anything.
OK.
Now, what we have to do, we have to step left and right subtree, so ASEP.
They lived separately and wrote separate, so separate is inbuilt function, so I will pass left and
right subtree.
OK, so after stepping what we have to do, we have to call this inventory function on subtrend right
subtree.
OK, so let's call inventory three function on left subtree.
OK, so dysfunction, this inverted function, this will return me the updated value of Lifespring,
so I will store that updated value of subtree.
And similarly.
Let us call in order to function on right subtree.
Now, this inventory function, it will update the right subtree and it will be done right separately.
So let's update the right subtree, OK?
Now, finally, our tree has been.
So finally, our tree has been inverted and we can likely now we can return root, OK, because our
tree has been inverted.
So in order to send our cold.
OK, so now let's admit.
OK, so our goal is working fine.
Now let's see how it is working.
Let us consider an example.
OK, so I have this appre.
When three.
Four, five, six and seven, OK, and this is my old.
This is my route, so this is the best case route is not.
Then I will swipe left and right.
So after stepping, it will look like this.
So when so I have three here, I have six, seven, and here I have two, four and five.
OK, then I'm calling the inventory function on the left separately.
OK, so this tree will be passed to the inventory function and similarly so in this line, what will
happen to left.
So basically this is the after forty six and seven is the right subtree.
OK, so they will be swept.
So after stepping, seven will come here and six will come here.
Then I will call the inventory function on this part on seven.
OK, so four seven.
Levasseur Presnell.
Right, separation if it will sweep null with null.
They are not any changes, OK?
No changes will be there, then it will return.
So I will come to three, then three will call on the right side.
I'm calling on the right subtree.
So for six, what it will do.
So it's a Presnell.
Its right.
There is also, if you will, step left and right subtree both undone.
So no changes will be there then six will return to three.
OK then three will return to one and then one, then the call will go to two.
OK, so for two goals fape it's left and right subtree.
So here Pfeifle come in here for Willkomm then five will call on left and right subtree so it will shrapnels
then five will return then two will now call will go to four, then four will call on its territory
which is null.
It will call on to try to separate which is agonal.
So Nele will be subdivisional so no changes.
And finally I am returning the ok finally I am returning RWD.
So when will we return.
OK, so this is how this is working, so the time complexities, because often we have to go through
each and every node.
OK.
So simple, so if you have any doubt in this question, you can ask me.
Thank you.