Content deleted Content added
m Minor Formatting |
→Vitter algorithm: A more accurate description of Vitter's Algorithm. Tags: nowiki added Visual edit |
||
Line 12:
===Vitter algorithm===
Some important terminologies & constraints :-
* '''Implicit Numbering''' : It simply means that nodes are numbered in increasing order by level and from left to right. i.e. nodes at bottom level will have low implicit number as compared to upper level nodes and nodes on same level are numbered in increasing order from left to right.
* '''Invariant''' : For each weight w, all leaves of weight w precedes all internal nodes having weight w.
* '''Blocks''' : Nodes of same weight and same type (i.e. either leaf node or internal node) form a Block.
* '''Leader''' : Highest numbered node in a block.
Blocks are interlinked by increasing order of their weights.
A leaf block always precedes internal block of same weight, thus maintaining the invariant.
'''NYT(Not Yet Transferred)''' is special node and used to represents symbols which are ''<nowiki/>'not yet transferred'''.
=== '''Algorithm :-''' ===
[[File:Leaf step one.png|thumb|'''Slide Method''' (leaf node): Slide_And_Increment(P) starts.
1. P is a leaf node.
]]
''leaf_to_increment'' = NULL
''P'' = pointer to symbol node
'''''Step 1 :-'''''
If (P is NYT) THEN
''BEGIN''
[[File:Leaf step two.png|thumb|'''Slide Method''' (leaf node): Slide_And_Increment(P)
2. As P is leaf node, it slides in front of next block nodes of equal weight.
]]
extend P by adding two children.
Left child becomes new NYT and right child is the new symbol node.
''P'' = parent of new symbol node
''leaf_to_increment'' = Right Child of P.
''END''
Go to Step 3.
[[File:Leaf step three.png|thumb|'''Slide Method''' (leaf node) : Slide_And_Increment(P)
3. Here we increase the current weight by 1.
]]
'''''Step 2 :-'''''
Swap P with leader of its block.
If (new P is sibling to NYT) THEN
''BEGIN''
''leaf_to_increment'' = P
''P'' = parent of p.
[[File:Leaf step four.png|thumb|'''Slide Method''' (leaf node) : Slide_And_Increment(P)
4. Method comes to an end.
P is the new parent.
]]
''END''
'''''Step 3 :-'''''
[[File:Internal one.png|thumb|'''Slide Method''' (internal node) :- Slide_And_Increment(P)
1. P is a internal node.
]]
while (P is not Root)
[[File:Internal two.png|thumb|'''Slide Method''' (internal node): Slide_And_Increment(P).
2. Node P slides in front of next block of nodes, with weight wt+1.
]]
''Slide_And_Increment( P )''
'''Step 4 :-'''
If ( leaf_to_increment != NULL )
''Slide_And_Increment( P )''
'''PROCEDURE ''Slide_And_Increment( P node ) :'''''
''BEGIN''
''previous_p'' = parent of p
''wt'' = weight of p
if ( p is Internal node )
[[File:Internal three.png|thumb|'''Slide Method''' (internal node) : Slide_And_Increment(P)
3. Now we increase the weight by 9. Thus the '''''invariant is maintained''''' as the current node is an internal node and should occur in front of leaf nodes of equal weight as we have increased the weight.
]]
Slide P in the tree higher than the leaf nodes of weight ''wt + 1.''
else
Slide P in the tree higher than the nodes of weight ''wt''.
''wt'' += 1
if ( p is internal node )
p = ''previous_p''
else
p = new parent of p.
''END''
[[File:Internal four.png|thumb|'''Slide Method''' (internal node) : Slide_And_Increment(P)
4. Now the 'P' points to the former parent ( as in the case of internal node according to algorithm)
]]
Encoder and decoder start with only the root node, which has the maximum number. In the beginning it is our initial NYT node.
When we transmit an NYT symbol, we have to transmit code for the NYT node, then for its generic code.
For every symbol that is already in the tree, we only have to transmit code for its leaf node.
====Example====
Line 65 ⟶ 153:
For the second "b" transmit 11.
It should be noted that for the convenience of explanation this step doesn't exactly follow Vitter's algorithm<ref name=":0">{{cite web|url=http://www.cs.duke.edu/csed/curious/compression/adaptivehuff.html#tree
Step 4:
|