Hi, everyone.
So in this video, we're going to solve this question, identical binary.
OK, so this is the problem statement.
So given to minorities, what we have to do, we have to check whether the two binary trees are equal
or not.
OK, so what is the meaning of equal to equal means?
Their value should be C each value should be the same and destructive should be.
OK, I will call to Binit recall when all the values are the same and the structure of the two minorities
are saying, OK, let us consider this example so to buy.
So this is driven.
And this is true, too, you can see, so driven by the values are all the same and the structures also
seem so, in this case I will return.
True.
OK, so that will be billion.
I have to return the value.
Whether there will buy new trees, I recall, or to buy any trees are not equal.
OK.
True or false.
Let us consider this example.
So basically the same one went to two, but the structure is different, OK?
So we're here to light in the laboratory and here to it.
Right subtree.
So in this case, I will return false.
They are not identical by nuclear.
OK, let us consider this example so they doctor same structure structuralism.
Now one one they are saying, OK, this no see here to the left hand side, but here too is present
in the right hand side.
So the values are different.
OK, all of the structure, same structure, same this one root node then left and right.
And similarly, this also has the same structure.
OK, same.
But the values are different here to this present here.
One is Besant similarly in the right to play here when it's present.
But here who is present.
So in this case, I will return false.
OK, so the question is very simple, given to minorities.
I have to check, I have to return to boolean value, whether to recycle or not.
So this is a very simple question.
OK, so how we can solve this question so we can solve this question with the help of recursion.
OK, we can very easily solve this question with the help of recursion.
So consider Daughtry's.
So this is driven the size of the plane ride subtree and similarly, I have to do so.
It will have its left and right.
Sudbury's.
OK, so when these two trees will be equal, very simple condition.
So everyone's left should be close to.
So first is basically the left should be close to the left.
Second is basically the ones right.
Should be close to Titos.
Right.
So dittos.
Divorce rate should be close to details, right, and the third is basically the value should be same.
OK, so basically the one value should be close to it.
Well, OK, I'm repeating myself when the Daughtry's will be equal.
When the two trains will be equal there, a very simple, simple condition, their values should be
same, the value should be equal to value.
Even left subtree should be close to details left Saberi, Devens right, Saberi should be close to
details.
Right, Saberi.
OK.
Now, how we can check whether we are equal or not, basically we will call recursion on it.
We will call recursion on it simple.
OK, we can write the code.
OK, so now let us likely write the code.
So this is the question, same tree.
OK, so after Rotana billion value, the name of the function is is same tree and it is sticking to
trees as input B and given the two trees.
OK, so let's change the name and be OK.
And we are the Daughtry's.
So first.
Let us write very simple, simple condition, so we've basically driven Isdell, OK, three one does
not exist and Preto does not exist.
So basically reasonable.
And tribesmen, if the tunnel, that means they are equal.
So if they are equal, I can return to simple.
Now, if everyone isn't Al.
Driven, seasonal, but Priebke is not only so Truby is normal and reasonable.
So this is very simple.
That means that both the trees are not equal because one is none.
Other one is normal.
So I can return false.
Similarly, the other way around IFPRI is Dardanelle.
And drib is Nele.
So if this is a scenario, then also I can return false because they will not be OK when this one is
not null.
Now, what is the condition that he and Drillbit they are seeing, so I will use these three conditions,
OK, I will use these three conditions.
So if all the conditions are true, I will return to those.
I will return false.
OK, so if all the conditions are true, I will return true.
Otherwise I will return false if any of the condition is false.
OK, so.
Let's so what should happen so evalu.
Should be close to be value.
OK, their value should be simple.
This is the first condition, second condition is basically their left subtree should also be seen.
So what we will do, we will take the function of a cemetery.
OK, this is a recursive function, so let's copy them.
Function name.
So is same tree, I will give it to trees, so I am giving the leaves a tree of tree and I'm giving
the A of tree.
OK, so this function is same tree function.
This will be true or false, whether through trees e left and be left with the same or not.
OK, this is recursive function and similarly I will call this function the same tree for the right
price.
OK, so I will, I have to give two trees so erate and be right.
So we've basically all the three conditions are true if this condition is true, if this basically.
So what is the work of dysfunction, so what is the work of is the same dysfunction?
So it will take two days as input and B and it will return a boolean value, whether they're three a.m.
or three a.m..
OK, so these are very simple, simple conditions.
Now, what I'm doing here is so when are the two trees will be equal?
When two trees will be equal?
When their values are the same, so if the values of A, B, if their values the same, if they live
surprising, so if they are left separately the same.
So but I will do I will call this function the same tree and I will give the left's.
I will give that left subtree of B OK.
It will return true or false requestion will handle OK because it will handle everything.
Now, again, there should also be some so I'm calling the function the same tree, I'm calling the
function the same tree, and I am passing their rates up.
So I'm giving the right set of I am giving the right set of me.
OK, now every I'm using and operated.
OK, so if all the conditions are true.
That means and B, they both have saying I can return, true.
I can return true.
Otherwise I will return false.
Simple.
So what I will do.
I will return true in the end part, what I can do.
I can return false.
Simple.
OK, our goal is working fine, Alert summered.
OK, so our goal is working fine.
OK, now a little bit of time, complexity and the space complexity.
So basically three letters, let's say this containing and notes and three B is containing amnot.
OK.
So these are the number of nodes.
So what I'm doing here is I'm basically going through each and every note of it and I'm going through
each and every note of be OK.
So all the time complexity.
So the time complexity will be emplacing.
OK, I'm going through each and all of that.
But in reality, the time complexity will be basically off minimum of Immonen.
Because if the laws are different, OK, see if the laws are different, this is a..
This is a..
That means the structure is different.
OK, that means the structure is different.
So if the structure is different with the help of these two conditions.
With the help of these two conditions, I will return false and my reaction will stop.
OK, so that's why I have written here the minimum of Immonen.
We will not explore the whole lot, so I will explore these nodes.
OK, simple.
So if you have any doubt in this question, you can ask me, ok.
The code is very simple.
OK, so if you have it out you can ask me.
Thank you.