 What up YouTube, like the code here today we're going to go over the tree Huffman decoding trees thingy. So basically you have like a string and of ones string of ones right ones and zeros and a Huffman coding is like a it's like this tree thing by it's like a tree where the right side is one and the left side is zero. Okay, so you're going to go go one to the right and go one to the left to zero right. So now what the the what the problem statement wants you to do is that given this tree and your string you want to decode it. So I'll explain how this decoding actually works. So let's bring up paint. Let's copy this picture. And let's copy this copy this take this do this and we'll just do this. Okay, okay, so I'm going to explain how this actually works and I'll explain how the output works. So let's say we're at this the starting a string of one. So we're given this string and we're given this binary search tree or a Huffman tree thingy. So what what it's going to do is it's going to look at your starting your starting string of ones and zeros and ones and zeros. So essentially what it's going to do is it's going to go to the right node to the right side if it's a one and zero if it's a it goes the left side of zero if it's a zero. And every time it hits a every time it hits a leaf node it's going to restart and go back to the top. So in this example here we have we're going to start at the first value of one. So it's going to go to the right of one. And then it hits this right because it goes to the right to the one and one is on the right side hits this and it goes a and since a is a leaf right it's just going to print a. And it's going to go back to the top of the node. So now once it prints a it's going to go all the way back to the top of the route. Now because we went back to the top of route now we're going to start to the second second value of zero. So we're going to go to zero now. And we're going to go to zero. So to go to zero it's going to go to left. Right. So because it's zero it's going to go to left and then afterwards we're not at a leaf yet. Right. We're not at a leaf. There's no it's not a leaf node yet. So it's going to go to the next portion. So right now we're here right going to go to the next zero. The next zero and then what is the next zero because it's a zero. It's going to go to the left node. So it's going to go to here. Right. Because it's zero. It's going to go to the left and then we're going to hit B and now because B is a leaf node. We're just going to print out B and we're going to go all the way back to the top. Okay. And the reason we know it's a leaf node is a leaf node is basically that the left and right child are no. So as you can see here there's no there's no children in B. Okay. So now that we hit B which is a leaf node. We're going to go all the way back to the top. Oh, whoops. Yeah, we're going to go all the way back to the top. So I'm going to erase this and we're going to go all the way back to the top. So it's now going to go to the root again. And now since we already finished the last two zeros we're going to go to this one. It's going to one. It's going to go to the right side. So it's going to go to here. So this part is a leaf right on the right side is a leaf. So we're just going to print a. Okay. So after we print a because it's a leaf, we're going to reset back to the top because we hit a relief. So we're going to go back to the top and to the top of the root. And then we go to the next. We're going to go to the next one. So we were at one before now we're going to go to the right part of zero. So I'm going to go to this part. This part zero. So now we're at the top of the root and we're going to zero. So it's going to go to the left side. So it's going to hit to this this part of this node Okay Now because it's not a leaf We're going to go to the next next node. So the next part of the string is this one This one this next one is the next part of the string. So because it's a one it's going to go to the right part So it's going to go to C Okay, so now because C is a leaf node. We're going to just print out C. So we print out C Okay, whoops my bad now that C is done Now we finished printing out the leaf node, right? And it's a leaf where it's going to reset back to the top of the root So now because we're resetting back to the top of the root We're just going to go all the way back to the top. So now now that we're back to the top We're going to go over here back to the top now because we're back to the top. We are going to go to the the next Next number which is going to be the last one is one and now it's one. So it's because it's one We're going to go to the right side. So going to the right side We're going to hit a and then we just print out and because a is a leaf node, right? There's no children. We're going to print out a and Yeah, and then now we're done with our string. So that's basically the reason why it outputted a b a C a Okay All right, so now I'm going to explain how the code works. It's just essentially what we're going to do is What I did was I created temporary node head that's going to always point to the root And what we're going to do is because we're going through this string We're going to actually loop through the string So we traverse from zero to the size of the string and then if it's a one We're just going to go to the right node root is going to go to the right and if it's a zero We're going to go to the left if we hit both if both of the left and right nodes are null Which means that both of these are not is nothing here, right? It means that we hit a leaf So if we hit a leaf, we're just going to Print out our data that we're currently on and then we're going to reset the root back to the head So we're going to reset our current current Current root Node is we're going to set it back to the head because I said head to the point of the root Originally first so now now roots is going to equal to head So it's going to reset back to the top and then this loop will continue running until it works So yeah, that's basically basically the gist of how this code works and I got a seat on this So yeah, hopefully you guys enjoy this video rate com subscribe. There's not not much to talk about here But yeah peace