 What's up guys, my name is Michael and welcome to my youtube channel today We're gonna do another depth first search question called same tree. We're given two trees You have to check if they're the same or not This is really easy actually Well first you have to check if they're both null if the root of each tree is null then You can return true because that means that there's no They both the trees are empty Otherwise you have to check if one is null and one isn't if one is null and one isn't then that means that it's false because that means that They have different values like if I have like in this case The right side is false is like no and then this right side is too so that's false then you have to check if each if the actual value is the same so like Two values the same as choose value from the left side of the tree and Then you just have to check if they're the same tree on the left side of the tree and the right side of tree So how do you do that? We'll just code it real quick if p is equal to null and Q is equal to null Turn true My my computer's lagging Else if if one of them is null or the other ones know return false All right the reason why we're able to do this is because We already know that in this case after this if statement that they're both are not No, so therefore this or statement would just check if one is no or the other ones know Right if one of this and all and the other ones know that means it's false Okay, we're able to do this because we know already that they're both are not no Okay, so that's why this else if works Then we have to check if the value is the same at both tree If that is the same return true Otherwise, um, yeah after that we're gonna return whether same tree on its left both of the trees left Trees and both of the trees right tree, and yeah, that's basically it Let's submit this Okay, I'm getting a wrong answer. What is the problem? Okay, whoops if it's not we return false, okay Okay, yeah, so the problem is is that if it's just cuz it's the same value P and Q that doesn't mean the trees the same right you have to check if like Well, if they're not the same then that's return false and then otherwise you have to go to you keep going to the same tree You have to check the left side in the right side. So that's the reason why we had to have this statement this statement Because we had to make it not equal because Just cuz one of them is true like one one that doesn't mean the whole tree is true like here in this case One one is true, right? They have the same value, but that doesn't mean that the whole tree is the same You have to still check the left side and the right side So that's why we we checked if it's not equal if it's not equal and then we need some return false Otherwise we have to check the left side on the right side. So yeah, that's how you do this question Right com subscribe. I hope you guys enjoyed my explanation and yeah, that's it. Peace out