0% found this document useful (0 votes)
36 views13 pages

Adaptive Huffman Coding Explained

Adaptive Huffman coding determines codewords using a running estimate of symbol probabilities to effectively exploit locality in data. It builds an optimal Huffman tree for the message seen so far and reorganizes it when needed. This allows compression in one pass over the data with overhead sometimes smaller than static Huffman coding. The FGK algorithm updates the tree by moving subtrees when a new symbol is encoded to maintain the optimal sibling property required for Huffman codes.

Uploaded by

MOVIETADKA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views13 pages

Adaptive Huffman Coding Explained

Adaptive Huffman coding determines codewords using a running estimate of symbol probabilities to effectively exploit locality in data. It builds an optimal Huffman tree for the message seen so far and reorganizes it when needed. This allows compression in one pass over the data with overhead sometimes smaller than static Huffman coding. The FGK algorithm updates the tree by moving subtrees when a new symbol is encoded to maintain the optimal sibling property required for Huffman codes.

Uploaded by

MOVIETADKA
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

20-02-2023

Adaptive Huffman Coding

Why Adaptive Huffman Coding?


 Huffman coding suffers from the fact that the
to compress a file some knowledge of the
probabilities of the symbols is required
 this can need more bit to encode the file
 if this information is unavailable compressing the file
requires two passes
 first pass: find the frequency of each symbol and
construct the huffman tree
 second pass: compress the file

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

1
20-02-2023

The key idea


 The key idea is to build a Huffman tree
that is optimal for the part of the
message already seen, and to
reorganize it when needed, to maintain
its optimality

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Adaptive Huffman Coding


 Adaptive Huffman determines the mapping to
codewords using a running estimate of the
source symbols probabilities
 Effective exploitation of locality
For example suppose that a file starts out with a series of
a character that are not repeated again in the file. In static
Huffman coding, that character will be low down on the
tree because of its low overall count, thus taking lots of
bits to encode. In adaptive huffman coding, the character
will be inserted at the highest leaf possible to be decoded,
before eventually getting pushed down the tree by higher-
frequency characters

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

2
20-02-2023

Adaptive Huffman Coding


 only one pass over the data
• overhead
In static Huffman, we need to transmit someway the
model used for compression
• sometimes encoding needs some more bits w.r.t.
static Huffman (without overhead)
But adaptive schemes generally compare well with static
Huffman if overhead is taken into account

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Adaptive Huffman Coding

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

3
20-02-2023

Algorithm
32 11

11
21 10
f 9

10 7 11 8

5 5 6
5 4
c d 5 e 6
3

2 3
a b
1 2
 Note that node numbering corresponds to the order in which the
nodes are combined by Huffman’s algorithm, first nodes 1 and 2,
then nodes 3 and 4 ...
DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

4
20-02-2023

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

5
20-02-2023

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm
 The basis for algorithm FGK is the Sibling
Property (Gallager 1978)
 A binary code tree with nonnegative weights has the
sibling property if each node (except the root) has a
sibling and if the nodes can be numbered in order of
increasing weight with each node adjacent to its
sibling. Moreover the parent of a node is higher in
the numbering

 A binary prefix code is a Huffman code if and


only if the code tree has the sibling property

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

6
20-02-2023

Algorithm(update procedure)

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm(update procedure)

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

7
20-02-2023

Algorithm FGK
Algorithm(update procedure)
32 11
33 b
Suppose next

11
21 10
symbol is “b”
f 9 22
 if we update the
11
10 7 11 8 weigths...
 ... sibling
5 5 6
c
65
4 d 5 e 6 property is
3 violated!!
2 43  This is no more a
a b
1 2 Huffman tree
no more ordered by
nondecreasing weight

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm FGK
Algorithm(update procedure)
33 11
32 b
12
11
21 10
f 9
6 10 7 11 8

4 5 5 6
5 4
c d 5 e 6
3
2 3
a b
1 2

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

8
20-02-2023

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

9
20-02-2023

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

10
20-02-2023

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

11
20-02-2023

Algorithm FGK - summary


 The algorithm starts with only one leaf node,
the 0-node. As the symbols arrive, new leaves
are created and each time the tree is
recomputed
 Each symbol is coded with its codeword in the
current tree, and then the tree is updated
 Unseen symbols are coded with 0-node
codeword and some other bits are needed to
specify the symbol

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

Algorithm FGK
 Algorithm adaptive huffman coding
compares favourably with static
Huffman code, if we consider also
overhead costs (it is used in the Unix utility
compact)
 Exercise
 Construct the static Huffman tree and the FGK tree
(adaptive huffman tree)for the message .Also
generate th ecode and decode the data.
 e eae deedba

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

12
20-02-2023

References:
 Data compression: Khalid Sayood.

 Animations

[Link]/~yklee/Courses/Compre
ssion/[Link]

DCE//SEM VI//Extc//Dr. Vishakha Kelkar

13

Common questions

Powered by AI

The 0-node in the FGK algorithm serves as the initial starting point for the Huffman tree and handles the introduction of new symbols. It is used as a placeholder for unseen symbols, allowing the algorithm to encode them with a 0-node codeword plus additional bits indicating their identity. As new symbols are encountered, they replace the 0-node leaf with new nodes specific to these symbols, updating the tree structure to incorporate them while maintaining the adaptive nature of the encoding process. This mechanism ensures the algorithm can handle dynamic symbol sets efficiently .

The primary advantage of Adaptive Huffman coding over static Huffman coding is its ability to adapt to changing probabilities of source symbols as they are read. Adaptive Huffman coding constructs and updates the Huffman tree dynamically based on a running estimate of symbol probabilities. This allows it to exploit locality of reference effectively, placing higher-frequency symbols higher in the tree and thus encoding them with fewer bits as their frequency increases during actual data compression. This results in more efficient compression in cases where symbol frequencies vary over the message, without needing a prior two-pass analysis of the data .

Updating the weight of a node can lead to violations of the sibling property in the Huffman tree. When a symbol's frequency changes, the weights of nodes in the tree need adjustments, potentially disrupting the established order where nodes must be ordered by nondecreasing weight. For instance, if increasing the weight of a node places it out of order with its sibling, this disruption requires dynamic restructuring of the tree to reestablish the sibling property, which is essential for maintaining an optimal Huffman code. Failure to address this can result in a tree structure that no longer supports efficient compression .

Adaptive Huffman coding's one-pass nature presents a practical advantage over the two-pass requirement of static Huffman coding. In Adaptive Huffman, the tree is built and updated dynamically during data reading, allowing real-time encoding without requiring a pre-analysis step to determine symbol frequencies, as in static Huffman. This single-pass process results in faster execution, particularly advantageous for streaming or real-time applications where waiting for a complete pass for frequency analysis is impractical. Static Huffman, in contrast, needs a full data pass to construct the tree based on fixed symbol probabilities, then a second pass to carry out the compression, introducing a delay and increased complexity .

The FGK algorithm handles new and unseen symbols by starting with an initial leaf node called the 0-node. When an unseen symbol is encountered, it is encoded using the codeword for the 0-node along with additional bits to specify the new symbol explicitly. This allows the algorithm to accommodate previously unseen symbols dynamically, updating the tree and symbol probabilities as they appear in the data stream, ensuring that new symbols are integrated into the adaptive model without interrupting the encoding process .

The trade-offs in using Adaptive Huffman coding compared to static Huffman coding involve bit overhead and processing complexity. Adaptive Huffman coding requires only one pass over the data, as it updates the model dynamically. This results in less overhead related to model transmission compared to static Huffman, which requires two passes and additional bits to describe the model. However, the adaptive method may sometimes require more bits than static Huffman in the absence of overhead, due to the constant updating process which may lead to temporary non-optimizations of the tree structure .

Adaptive Huffman coding exploits the locality of reference by dynamically updating the Huffman tree as it processes the data, allowing it to adjust symbol probabilities on-the-fly. If a certain character starts appearing frequently in a segment of data, it is quickly moved higher in the Huffman tree, reducing its code length during the period of increased frequency. This adaptability results in more efficient compression when data exhibits non-uniform symbol distribution, as the algorithm continuously optimizes the tree structure to reflect recent symbol statistics, reducing the space required to encode recent frequent characters .

The FGK algorithm ensures optimal Huffman tree encoding by maintaining the sibling property, which is the basis of Huffman's coding. It starts with a single leaf node and builds the tree incrementally as symbols are received. Each symbol is encoded using the tree constructed from the symbols seen so far, and the tree is then adjusted. When a new symbol arrives, its count is updated, potentially leading to tree restructuring to maintain the sibling property, ensuring the tree remains optimal. This design allows the algorithm to accommodate symbols dynamically, maintaining efficient code-length representation as the dataset evolves .

Static Huffman coding might be preferred over Adaptive Huffman coding in scenarios where significant processing overhead or slight efficiency loss is acceptable due to the simplicity of static coding. For instance, when symbol probabilities are known a priori and uniform across a file, static coding can be more efficient as it can avoid the continuous tree restructuring required by adaptive methods. Additionally, in cases where data structures like file headers or known content types are involved, where probabilities don't dramatically change, static coding's efficiency and simplicity can outweigh the adaptive overhead .

In the FGK algorithm, the sibling property is crucial for maintaining the integrity of the Huffman tree. This property ensures that each node (except the root) has a sibling and nodes are numbered in order of increasing weight, with each node adjacent to its sibling. When symbols' frequencies are updated, ensuring the sibling property prevents violations that could lead to invalid Huffman coding practices. The parent of a node must be higher in the numbering to maintain a proper prefix code, which is the hallmark of a Huffman code, allowing efficient data representation .

You might also like