 Alright guys, today we're going to go over tree level order, I think level order traversal. Yeah, I've not done this yet. Um, actually, I did do this problem, but like, I haven't gone over on YouTube yet. Okay, so today we're going to go over tree level order traversal. So when they say level order traversal, it means like each level. So in this case, um, let's say your trees looks like this, it's going to go level by level. So from left to right, so we have one, then we have nothing here. And then we have two, right, and then we have nothing on this side, then we have five, then we have nothing on these sides, and then we have three, then we have six, right, because they're on the same level here, and then we have nothing on the left side, and then we have four in the end. So to do the, to do this problem, um, it's actually not that hard. I don't know if there's a recursive solution, but I know there is a breath first search solution. So I'm going to just go over breath first search, how to do this breath first search. All right. So here's what you do. We're going to run breath first search and we're going to just push the current node. Um, yeah, we first going to push, we have a queue called line, which is going to represent like the line that the order that we're going through for each level, right. And what we're going to do is we're going to push, push the current node of the route on it, because that's what we're going to start at. We're going to start at one, we're going to push that. And what we're going to do is we're going to check while the line is not empty. So if the line's not empty, then we're going to continue printing out the values in each line in each level. So here's how it works. First, we're going to get the first node, which is from the first line. And what we're going to do is if it's not null, it's not equal to null, we're just going to print out the data of what it is, right, the data of the node. Okay, the first line, if it's not equal to null, we print out the data. All right, then what we're going to do, we're just going to push the left side and the right side. So we're going to push the node on left and the node on the right. So what I do is I have to check if it's not equal to null, then I could push it. So that's why I do that here. Yeah. So if it's not equal to null, we'll push the left side first left. And then after that, we check if the right side is not equal to null, then we push the right side. So yeah, then we push left side, we push the right side, then we keep doing that push left, push right. And then after we push left and push right, we're going to pop. So we're going to remove the first value of our list from the first value. And we're just going to continue doing this over and over again. And then each time we get the first value, and then we print the node node's data. And then we have spaces. So the reason why this works is if I could just show you guys an example and why it works, explain why it works. So let's say I have this. Okay, let's have this right. All right, what we're going to do is we start at the top one, we add this to our queue. So let's actually call this the queue is our line. Okay, we add one. And what does it do? We add one. And then if it's not empty, we're going to we're going to print it out. So we're going to print out the first value. So it's going to print out one. Okay, then what we're going to do, we're going to push the left side if it's not null, and the right side. So left side here is null. So we don't do anything. And then otherwise, we got to push the right side of two. So we're going to push two. Okay. Then after that we pop it. So we pop this is off. And then we go to two. All right, we get the front of the two. So now we're going to know we're here. Okay, now we're here on this level. Then, then what we're going to do is we're going to on Tuesday level, we're going to print out to because it's not null. So print out to write, we print out to their current node. And we got to push the left side and the right side. So left side is null. So we do nothing. Right side is not null. And then we're going to push five, push five here. And then after five, yeah, after push the right side, we pop it. So then we move to so two is gone from our queue. So yeah, then what we're going to do is we're going to go to the five. So what is five? So now we're here. So now we are here at five. We're going to push three and six, right? Because that's the left side and the right side. So we're going to push three and then we push six. I'll go to the site. And six, then we're going to pop five. So pop fives get popped. And oh, yeah, by the way, while we were at five, we print out five, by the way. Yeah. And we pop five. So now fives off. And then now we get the front of the node, which is three. So now we're at three. Okay. Now we're at three. We're going to print out three. So it's going to print out three. And then what we do is we got to push the left and right. So what is the left? Left is null. So we can't do anything. Then we push right, just four. So we push four onto the stack, not stack the queue, push four. Okay. Then after that, three is popped. So we move three, three is popped. And then now we're going to get the next node, which is going to be six. Right. Six is going to be the next one here. Now we're here. Now we're at six. We're going to just push left and right and left and right are null. We do nothing. So here you're nothing. And then at the end, we print out six. So now we have one, two, three, five, six, right. And then after that, we just pop six. So six is popped. So now when six is popped, we go to the four because four is the next node on the queue. So now we're at the queue of four and we push left and right. Left and right are both null. So we don't push anything. And yeah, at the end, we pop four. We got to print for it though. Print four. Then we pop four. And then four is gone. So yeah, if you look through the nodes here, we have one, then two, then five, which each level, then we have three, six, then we have four. So yeah, this is what we have. So yeah, that's the reason why this works is because if we run breath first search, it actually goes on to the previous line that we had, and we popped those. So yeah, that's how you do this problem. I hope you guys enjoyed this video. Don't forget to subscribe. I'll check you guys later. Peace.