A text is made up of the characters a, b, c, d, e each occurring with the probability 0.11, 0.40, 0.16, 0.09 and 0.24 respectively. The optimal Huffman coding technique will have the average length of :
2.16
Huffman coding is a popular algorithm for lossless data compression. It works by assigning variable-length codes to characters, where the length of the code is inversely proportional to the frequency (or probability) of the character. More frequent characters get shorter codes, and less frequent characters get longer codes. This strategy minimizes the total length of the encoded text, resulting in optimal compression.
The algorithm constructs a binary tree, called the Huffman tree, based on the probabilities of the input characters. The process involves repeatedly merging the two nodes with the smallest probabilities until only one node (the root) remains.
We are given the following characters and their respective probabilities:
The Huffman algorithm proceeds as follows:
Let's sort the probabilities:
Step 1: Combine the two smallest probabilities (0.09 and 0.11).
New node probability = 0.09 + 0.11 = 0.20
Remaining probabilities: 0.16, 0.24, 0.20, 0.40
Sorted: 0.16, 0.20, 0.24, 0.40
Step 2: Combine the two smallest probabilities (0.16 and 0.20).
New node probability = 0.16 + 0.20 = 0.36
Remaining probabilities: 0.24, 0.36, 0.40
Sorted: 0.24, 0.36, 0.40
Step 3: Combine the two smallest probabilities (0.24 and 0.36).
New node probability = 0.24 + 0.36 = 0.60
Remaining probabilities: 0.60, 0.40
Sorted: 0.40, 0.60
Step 4: Combine the two smallest probabilities (0.40 and 0.60).
New node probability = 0.40 + 0.60 = 1.00
This is the root of the tree.
Based on the merging steps, we can visualize the tree and assign codes. Assigning '0' to the left branch and '1' to the right branch at each split, we get the following codes and lengths:
Now, we calculate the average code length using the formula:
$\text{Average Length} = (P_a \times L_a) + (P_b \times L_b) + (P_c \times L_c) + (P_d \times L_d) + (P_e \times L_e)$
Substitute the probabilities and lengths:
$\text{Average Length} = (0.11 \times 4) + (0.40 \times 1) + (0.16 \times 3) + (0.09 \times 4) + (0.24 \times 2)$
$\text{Average Length} = 0.44 + 0.40 + 0.48 + 0.36 + 0.48$
$\text{Average Length} = 0.84 + 0.48 + 0.36 + 0.48$
$\text{Average Length} = 1.32 + 0.36 + 0.48$
$\text{Average Length} = 1.68 + 0.48$
$\text{Average Length} = 2.16$
The optimal Huffman coding technique for the given probabilities results in an average length of 2.16.
| Character | Probability ($P_i$) | Huffman Code | Code Length ($L_i$) | $P_i \times L_i$ |
|---|---|---|---|---|
| a | 0.11 | 1111 | 4 | $0.11 \times 4 = 0.44$ |
| b | 0.40 | 0 | 1 | $0.40 \times 1 = 0.40$ |
| c | 0.16 | 110 | 3 | $0.16 \times 3 = 0.48$ |
| d | 0.09 | 1110 | 4 | $0.09 \times 4 = 0.36$ |
| e | 0.24 | 10 | 2 | $0.24 \times 2 = 0.48$ |
Sum of $P_i \times L_i = 0.44 + 0.40 + 0.48 + 0.36 + 0.48 = 2.16$
| Concept | Description | Importance |
|---|---|---|
| Huffman Coding | A greedy algorithm for optimal prefix coding. | Lossless data compression. |
| Prefix Code | No code is a prefix of another code. | Enables unambiguous decoding. |
| Average Code Length | Expected number of bits per character in the encoded text. | Measure of compression efficiency. |
| Greedy Algorithm | Makes locally optimal choices at each step with the hope of finding a global optimum. | Used in constructing the Huffman tree. |
Data compression aims to reduce the number of bits required to represent data. There are two main types: lossless and lossy. Huffman coding is a lossless compression technique, meaning no information is lost during compression, and the original data can be perfectly reconstructed from the compressed data.
A key property of Huffman codes is that they are prefix codes (also known as prefix-free codes). This means that no code is a prefix of any other code in the set. For example, if 'a' is coded as '01', no other character can have a code starting with '01'. This property is crucial because it allows for unambiguous decoding of the compressed bitstream. As soon as a complete code for a character is read, it can be decoded without needing to look further ahead in the stream to see if it's a prefix of a longer code.
Huffman coding is widely used in various compression formats and protocols, including zip, gzip, JPEG, and MP3.
Match List-I with List-II:
List-I | List-II |
(a) Greedy best-first | (i) Minimal cost (p)+h(p) |
(b) Lowest cost-first | (ii) Minimal h(p) |
(c) A* algorithm | (iii) Minimal cost (p) |
Choose the correct option from those given below:
A text is made up of the characters A, B, C, D, E each occurring with the probability 0.08, 0.40, 0.25, 0.15 and 0.12 respectively. The optimal coding technique will have the average length of:
Which among the following statement(s) is(are) FALSE?
A. Greedy best‐first search is not optimal but is often efficient.
B. A* is complete and optimal provided h(n) is admissible or consistent.
C. Recursive best‐first search is efficient in terms of time complexity but poor in terms of space complexity.
D. h(n) = 0 is an admissible heuristic for the 8‐puzzle.
Suppose there are six files F1, F2, F3, F4, F5, F6 with corresponding sizes 150 KB, 225 KB, 75 KB, 60 KB, 275 KB and 65 KB respectively. The files are to be stored on a sequential device in such a way that optimizes access time. In what order should the files be stored?
If b is the branching factor and m is the maximum depth of the search tree, what is the space complexity of greedy search ?