Adaptive Huffman coding: Difference between revisions

Content deleted Content added
Line 34:
 
'''algorithm''' for adding a symbol '''is'''
leaf_to_increment := NULL
p := pointer to the leaf node containing the next symbol
'''if''' (p is NYT) '''then'''
Extend p by adding two children
Left child becomes new NYT and right child is the new symbol leaf node
''p'' := parent of new symbol leaf node
leaf_to_increment := Right Child of p
'''else'''
Swap p with leader of its block
'''if''' (new p is sibling to NYT) '''then'''
leaf_to_increment := p
''p'' := parent of p
'''while''' (p != NULL) '''do'''
Slide_And_Increment(p)
Line 55:
 
'''function''' Slide_And_Increment(p) '''is'''
previous_p := parent of ''p''
'''if''' (p is an internal node) '''then'''
Slide p in the tree higher than the leaf nodes of weight wt + 1
increase weight of ''p'' by 1
''p'' := previous_p
'''else'''
Slide p in the tree higher than the internal nodes of weight wt
increase weight of ''p'' by 1
''p'' := new parent of ''p''.
 
Encoder and decoder start with only the root node, which has the maximum number. In the beginning it is our initial NYT node.