Huffman Paraphrased
Huffman Paraphrased
COMMUNICATION NETWORKS
PROJECT REPORT
HUFFMAN CODING IMPLEMENT
Contents
Abstract .......................................................................... 2
Theory............................................................................. 2
2) Huffman Tree.............................................. 4
FLOWCHART ................................................................... 7
Implementation .............................................................. 7
Conclusion .................................................................... 24
References .................................................................... 25
Abstract
The Huffman Coding is a lossless
data compression algorithm,
developed by David Huffman in
the early of 50s while he was a
PhD student at MIT. The
algorithm is based on a binary-
tree frequency-sorting method
that allow encode any message sequence into shorter
encoded messages and a method to reassemble into original
message without losing any data.
Theory
1) The Basics
2) Huffman Tree
a) Definition
The best way to visualize the Huffman coding is to think of it
as a tree, a Huffman tree. A Huffman tree is comprised of
binary whose leafs correspond to characters.
The length of a leaf is amount to the length of the bit
sequence corresponding to the character. The Huffman tree
is the binary tree with minimum external braches weight so
the goal is to build a tree with the minimum external
branches.
FLOWCHART
Implementation
Implement in C language
#include <stdlib.h>
return temp;
}
// current size is 0
minHeap->size = 0;
minHeap->capacity = capacity;
minHeap->array
= (struct MinHeapNode**)malloc(minHeap->
capacity * sizeof(struct MinHeapNode*));
return minHeap;
}
// A utility function to
// swap two min heap nodes
void swapMinHeapNode(struct MinHeapNode** a,
struct MinHeapNode** b)
if (smallest != idx) {
swapMinHeapNode(&minHeap->array[smallest],
&minHeap->array[idx]);
minHeapify(minHeap, smallest);
}
}
--minHeap->size;
minHeapify(minHeap, 0);
return temp;
}
++minHeap->size;
int i = minHeap->size - 1;
minHeap->array[i] = minHeapNode;
}
int n = minHeap->size - 1;
int i;
printf("\n");
}
minHeap->size = size;
buildMinHeap(minHeap);
return minHeap;
}
{
struct MinHeapNode *left, *right, *top;
top->left = left;
top->right = right;
insertMinHeap(minHeap, top);
}
arr[top] = 0;
printCodes(root->left, arr, top + 1);
}
arr[top] = 1;
printCodes(root->right, arr, top + 1);
}
{
// Construct Huffman Tree
struct MinHeapNode* root
= buildHuffmanTree(data, freq, size);
return 0;
}
Conclusion
References
[1] https://sites.fas.harvard.edu/~cscie119/lectures/trees.pdf
[2] http://homes.sice.indiana.edu/yye/lab/teaching/spring2014-C343/huffman.php