Professional Documents
Culture Documents
The program gives u a MINIMUM VARIANCE Huffman Coding. The Source code is
pretty well documented and doesnt require much more elaboration. However, I will just
clarify a coupla things -
I. I/O Format:
a. First you must enter the no. of lines that ur input will roughly occupy
b. Then enter the string taking care that only the following character-sets are allowed
i. 'a--z'
ii. 'A--Z'
iii. '0-9'
iv. ' ' (SPACE)
v. '\n' (NEWLINE)
c. Sit back while your computer encodes and presents u the requisite code :P
II. ALGORITHM:
The basic concept/Algorithm is :
1. Let ' frequency[ ] ' be a 1D integer Array. "frequency[ i ]" represents the
Frequency of the ith symbol.
Let 'code[ ][ ]' be a 2D Character Array, where : ' code[ i ] ' represents the
Code for the ith symbol.
2. Assume that we have an ASCENDING ordered Singly Linked List (ordered as per Cumulative
Frequency AND Alphabetical Precedence)
4. The SLL is ordered on the basis of Relative Frequencies of Alphabets of the Root of the Binary
Tree pointed by ' *btroot ' & as per the Alphabetical order of Root Nodes of the Binary Tree.
6. Let ' position[ ] ' be a 1D pointer array, where " position[ i ] " contains a
Pointer to the Binary Tree Node of the ith sybol.
7. Initially, ALL the Symbols are created as DISTINCT Binary Trees, each with
only a single 'root' element. As they are created, ALL these DISTINCT Binary
Trees are pushed into the Ascendingly Ordered SLL, in such a way that the
Ascending Property is maintained. Also, set : position [ i ] = p, where 'p' is
the Distinct Binary Tree Root just created & inserted.
8. Then,
While ( SLL contains more than 1 element)
{
(a) Remove from the SLL, 2 Min Binary Tree Nodes, say p1 & p2
(Min as per Relative Freq. & Alphabetical Order)
10. STOP