 Hello everyone. Welcome to this session. I am Mr. Praveen Yalapa Kumbar. Today we want to see adaptive Huffman coding. The learning outcome of this topic is, at the end of this session, students will be able to explain the concept of adaptive Huffman coding algorithm in lossless compression. The contents of this topic are introduction, procedure for adaptive Huffman coding, sibling tree property, tree update rules, and with the help of this tree update rules, we can see the example introduction. The Huffman code algorithm requires the knowledge of input data in advance to find out the frequency of occurrence of e-symbol. But if we observe in the live applications, we don't know what is the input data. Therefore, for the live application, this Huffman code algorithm is not useful. Therefore, we use adaptive Huffman coding for the live videos and adios, we use adaptive Huffman coding in these cases. Procedure for adaptive Huffman coding. Now for the encoder, first of all initialization the code with the assumption of some data. After that one, while we use the condition that is a not Eof, Eof means end of file. After that one, we will get C, C means what code, getting the code. After that one, we will encode the code. Then with the help of this encode procedure, we can update the tree with the help of that code. For the decoder, initialization the code. After that one, we use again here while condition, while not Eof, Eof means end of the file. After that one, we decode the code, which will transmit with the help of the encoding. In the decoder, we decode that code. After that one, we see the output of that code and again make a necessary changes in the tree and that will make the update tree with the help of that code, sibling tree property. The binary tree should satisfy the sibling property. Sibling property states each node except the root has a siblings and the nodes can be listed in order of non increasing weight with each node adjacent to its siblings. The node numbers will be assigned in a such a way that a node with a higher weight will have a higher node number. Second one is a parent node will always have a higher node number than its children. For weight of the parent node is equal to the sum of weights of its two child nodes. Now we want to consider in this example the first we will see the root. W means weight, n means node number. See what is a means of weight, what is a means of node, how this come 5, 9, we see the letter words with the help of example. First of all you consider this diagram in this one in this algorithm. First we want to satisfy the property or not we want to check in this example. Now what is the first property a node with a higher weight will have a higher node number, higher weight higher node number. And compare with this one this is a lower weight that's why this is a lower node number. Now if you compare this example the satisfy the first property yes the satisfy the first property. Now second property is a parent node will always have a higher node number than its children. Now here the parent node is this one and this is a child nodes. Now the parent node will always a higher node number. Here the higher node number is always greater than this child node yes this second property is also satisfied. Now we consider one another example if you consider in this example what will happen here if we observe here for the R code weight is 2 and n is 5 here weight is 1 and n is 6 but here the adaptive Huffman code is violated because a node with a higher weight should have a higher node number. Here weight is 2 and n is 5 but if you observe here weight is 1 and n is a 6 that's why here n is always large but if you compare with this one this child what will happen the weight will be the less as compared to this node number therefore this adaptive Huffman coding is violated that's a not satisfied. Now what we'll want to do for if this situation comes we want to see next. Now n yt n yt means not it transmitted now w means weight here n is a node node is equal to 2n plus 1 where n is the total number of unique words. For example if we consider example now I want to transmit this a b cd here total n is what 4 but now we consider another example that is a a b cd but n is what total unique words here n is not 5 why because here a consider as a unique word 1 b as a 2 c as a 3 d as a 4 therefore here also n become as a 4 for this example for both this example capital N that is a node becomes 2n plus 1 that is 2 into 4 plus 1 that is 9 in this example. Now n node should be increased from left to right and bottom to the top this is a rule for the node now we have to consider for example a a r d v now from this question you have to recall what is the number of n okay here n is equal to 4 now how this 4 becomes this double a consider as a one symbol r is a second d is a third v is a 4 therefore n is equal to 4 now put this value into the capital N that is 2n plus 1 that becomes 9 tree update rules now here tree is a construction constructed using the following rules now you are taking as a question as a previous question we have to continue and we have to draw this tree for this question now what is the question that I want to transfer the data a a r d v now for this one the first rule for this tree update is every tree contains a root and a n y t node where the n y t node is the node with the lowest order in the tree and with the zero weight now this is a represented with the help of this diagram and here weight and the node now second rule when a character is read in from a file the tree is first checked to see if it always contains that character if not then the n y t node spans into two new nodes the node to its right is a new code containing the character and and the left node is a new n y t node update weights for all the nodes in the parent chain if the character is already present in the tree then you simply update the weight of the particular tree node and update the weights for all the nodes in the parent chain now for example for the we consider as a input a now for that input a you can consider as a root n qt w is a weight zero and n is a node that is a nine now for that one you again goes to the n y t n y t means not it to be transferred here weight is zero and here n is a seven because n is a maximum number we have to get nine after that the previous of number for the nine is seven and eight now always remember lower number in between the seven and eight always write towards the left and the maximums of that number towards the right therefore i will write here seven and the next number is a because i want to transmit the data a that is one and the n is a now eight therefore for the n nine here left most seven and right most is a eight number then i want to transmit again this is what again there's a previous one a now when i want to transmit again another number that is a now here a you have to check whether a is a transmitter already yes sir you we already transmitted a then simply for this one i want to update here a now what will become here a weight becomes two n becomes eight now that's a simply shows with the help of this one here weight becomes two why because the previous one is a one and again i want to add the eight then it will becomes two the number will become the same no problem seven eight now this is a what parent node now i want to add zero plus two that is two the next symbol for that one i want to add this one again symbol i want to transmit that is a r now in this one i want to add here after this diagram we will get see for this zero and seven i want again go to the n y t and again i want to add this r symbol always remember whenever i want to transmit the new data always add to the left hand side of the previous one therefore here this n y t and this number is seven then it becomes as a five and here become it is a six and here i want to transmit r therefore it will the weight becomes one now after that one adding the zero and one you get the weight is a one and n is a seven now after that adding a a r i want to add the next bit that is a d after the adding of a d always remember it will add to the left hand side therefore it will become as n y t zero n three and d will be add to the right most side and this weight is one and n will become the four now after adding this d symbol this n y t goes off and it will become as here n y t goes off and n y t comes to here and update the weight with the help of this one zero plus one that is weight one and after that one this one plus one will become as a two this two plus two become as a four in this way i want to transmit the a a r d and this is a tree diagram now after that one i want to again transmit the v symbol now if you want to transmit the v symbol then again according to the rule it will add to the left hand side of this n y t then it becomes as n y t zero n one and for that i want to transmit this v symbol that will become w is equal to that is weight one and n is a two after that when we want to update all these parent nodes then it will become as w is equal to one n is equal to two how it becomes zero plus one that is a one and n is a three one plus one two two plus one three three plus two it will becomes as a root as a five now after the transmission of this all these symbols now i want to check their rules the first rule is what a node with a higher weight should have a higher node number but if you observe here n is equal to five w is equal to two n is equal to six and w is equal to one this condition at this level is not satisfied therefore we must go to the again new rules what is that rules when the node is not the highest order node in its weight class you will need to swap this node so that it fulfills the property that nodes with a higher weight have higher order to do this before you update the nodes weight search the tree for all nodes of equal weight and swap this soon to be updated value with the highest order node of equal weight and finally update the weight now apply that rules into this previous diagram now the after the applying this one we want to swap these to the this one and after that one will be the update that according to that one now after the swiping that one we get now now a node with a higher weight should have a higher node number this is the rules we have to follow and if you observe here again is there also not satisfied in that one again we want to swap and according to that one we get a new tree as such as this one we get the new tree after the swiping you have to check whether there is again there is a condition is satisfied or not if satisfied again you have to update the root values references for this topic are thank you