Highly even so in this video, they're going to solve this question symmetric by Nutri.
OK, so they will basically be a binary tree and we have to return, whether that by Newton's symmetric
or not.
OK, so basically the return type is basically a boolean value.
I have to return.
True or false?
True.
If the given tree is basically symmetric tree, otherwise I have to return false.
OK, so let us consider an example and let's see what is a symmetric by nutri.
So let us consider this example.
So what I will do, I will draw a centerline.
OK.
Now, I will compare the values, I will compare the values, so in this case, so I will compare the
value as well as the structure.
OK, so I will compare.
Value and structure, both should be seen on the left and the right hand side of this middle line.
OK, now values I seem to want to and also distances seem if this distance is this distance is also
OK.
So value and distance assim.
Now let's move ahead.
Let's compare for to so for and for values the same distances also same BMV.
Now compare three with three.
OK, so if the distance is this distance is already ok.
And again the values are same.
So basically this tree, this tree is a symmetric tree so I will return.
True.
OK, now let us consider this tree.
So industry.
First of all, it does draw the line.
And now let us compare the values and the structure, OK, values our same distances, also same let's
call it the.
So in this case, values are simply entry, but the states are different.
So in this case, let's call it divine.
And this distance is basically data.
OK, so this is not a symmetric boundary, OK?
This is not symmetric.
So I will return calls for this by nutri.
OK, so I hope you understood the question.
Now suppose this is the root node now.
Root node.
This is the left subtree.
Let's call it three one.
This is the right subtree of the root.
Let's call it due to OK, Rita.
Driven driven to do so when this.
So what is the condition for this tree to be a small victory.
OK, so there are very small, small conditions.
So first condition is basically.
If the values of OK, so basically first condition is Wellinghoff, everyone's ruled is equal to the
Valley of the Dolls to.
OK.
The second condition is basically.
The events left subtree.
Should be symmetric with details, right subtree.
OK, so we can see here I am comparing.
OK, so this is everyone, let's call it Reto.
OK, so 41 if I'm calling with the left hand side, so 42, I will call on the right and say, OK,
so 41, this is left 42.
This is right.
OK, so everyone's left should be close to it should be symmetric to deduce.
Right.
And a third condition is basically the ones.
Right.
Should be symmetric to reduce left.
OK, so these are the very simple, simple conditions.
Now, what we can do, we can we can make the help of recursion and we can solve this question with
the help of these three conditions.
OK, you can see here so 42 if I'm comparing four.
So I will call on the right hand side, but 42 to compare for.
I will call on the left hand side.
OK, so I hope you understood the question.
Now let us write the code, OK, remembering these three conditions.
So basically, they of the function is asymmetric, we have to complete this function, then put as
basically a tree and the return type is whether they're given trees symmetric or not.
OK.
So first of all, the base case.
So if rotational, then I can say that given today's symmetrical, so I can return to.
OK, so now let us create a helper function.
OK, so.
Let us create a helper function which will do our work so that it will obviously be able I have helper
function, so it will take two tries to compare.
OK.
It will take two raise as input, so the left separates the left and the right tree.
OK, so this helper function will do our work and what I will do, so let us call this function helper
function and I will pass the left and the right subtree.
OK, so what I am doing here is so basically I am creating a helper function.
OK, and this helper function will take place as input and it will compare these duties.
OK, so, for example, let us consider this.
So this helper function will take this tree as input.
So it is stored in the left variable and this tree will be stored in the right variable.
OK, so I comparing these two trees.
Two, three, four, and the right is basically two for three, OK, I am passing the left subtree and
I am passing the right subtree.
OK, so now let us complete the court.
So the court is going to be very, very simple.
Now, let us take care of a few situations, a few simple, simple cases.
OK, so case number one.
So if the left Presnell.
And the right tree is not.
OK, so basically the right tree is nocturnal, then they are not symmetric.
So I can return false.
Simple.
Now, similarly.
So if the left today is not OK, left pre-exist, but right, it does not exist, so right, reasonable
and left is not null, then also I can return false.
Simple now, if the values are different, OK, so if the value of lefty.
It's not a close to the valley of right tree.
Then in that case, I can also return false.
Simple.
OK, so if the levels are Presnell and right, if not, then return false.
If the left is not all right, then then also return false.
If their values are different, then also return false.
They are not symmetric.
OK, so force structure should be same and the values should also be the same.
Now, there can be one more condition if the tunnel OK.
If both left and right, so in that case, I can return to.
So if left and right is also nil.
Then I can return true safely.
OK, so these are very simple, simple conditions now what we have to do.
So I have to make use of these two conditions, OK?
I will make use of these two conditions.
We have already handled this one, OK, if you will see the code, we have already handled the condition.
Now let us handle these two conditions.
OK, I have to pass the left.
And was right, and similarly, if he wins right, then it's left.
OK.
So the name of the function is helper.
So, OK, I have to change the name, because you can see left and right have already been used.
OK, so let's name it left three.
And this is right, three.
OK, so now that is called helper function, and we will take we will make use of these two conditions.
OK.
So.
If left three.
So if I'm giving the left three left, then I have to give right three, right.
So these two trees should be symmetric and.
If I'm giving.
The left three right, then I have to pass the left of the right tree.
OK.
So right we left.
Very simple.
OK, so this is basically driven this is basically to do OK, so this is route.
Everyone is this one and two is this one.
OK, so these are very simple, four conditions.
OK, now I'm calling the helper function.
So for the helper function.
If I am passing through, you once left, so Trillanes left, that means decide, OK, three months
left, then I have to pass it right.
So Britos right.
OK, then only they will be at the same distance, so if this distance is deep, then also this distance
will be OK and we are using and OK.
And if I am comparing Even's, right.
So this is the once right, then I have to compare it to the left.
So this is due to the left.
OK, this distance is deep, then only this distance will be OK if everything if this whole tree's symmetric
to this tree we are using the end condition, then only I will return to OK, otherwise I will return
false.
OK, very, very simple.
So what is the complexities or time complexities big often.
And the space complexity is also big, often due to recursion.
OK, so very simple and very logical.
OK.
OK, so now letters are now called.
OK, so we are getting random error at this lane.
Now let's see why.
OK, so obviously we will get rain tomorrow, and I suppose if the left reasonable, if the left Presnell,
then how can you assess the value of nil?
And similarly, if the right reason, then how we can assess the value of nil.
So that's why we are getting there in time.
OK, so to solve this problem, what can I do so I can write this line below this line?
OK, so I will write line number 16 before line number 15.
OK, that will solve our problem.
Now, let's see.
So just remove this line and write this line the last, OK, so I have to write this line after this
line because headline number 15, I am checking if left reasonable and retrieve the boat and then return.
True.
OK, so when we will reach line number 17, I am very sure that left, pre-exist and right also exist.
OK, so now if you will run call.
Our goal will work fine, hopefully.
OK, now let's admit.
OK, so our goal is working for success.
OK, so if you have any doubt, you can ask me.
Thank you.