Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

n-ary Huffman Template Algorithm

0.00/5 (No votes)
12 Nov 2002 1  
The algorithm allows any kind of weights (costs, frequencies), including non-numerical ones

Introduction

Web page :
http://alexvn.freeservers.com/s1/huffman_template_algorithm.html

Download :
http://www.simtel.net/pub/pd/60300.shtml
http://home.barak-online.net/alexvn/s2/hf/hufnta22.zip



The algorithm allows any kind of weights (costs, frequencies), including non-numerical ones. The {0, 1, ..., n-1} alphabet is used to encode message. Built tree is n-ary one.

The algorithm is based on a set of template classes :
- Cell(SYMBOL, WEIGHT),
- Node(SYMBOL, WEIGHT),
- InternalNode(SYMBOL, WEIGHT),
- TerminalNode(SYMBOL, WEIGHT),
- BasicHuffmanTree(SYMBOL, WEIGHT, ARY),
- LoadedHuffmanTree(SYMBOL, WEIGHT, ARITY),
- DriedHuffmanTree(WEIGHT, ARITY).
The user should use only LoadedHuffmanTree and/or DriedHuffmanTree classes.
LoadedHuffmanTree requires (as input data) the symbols and their weights.
DriedHuffmanTree requires (as input data) only the weights.

The program contains the following tests :
* Creating Loaded 5-ary Huffman Tree from data vector with char-symbols and int-weights;
* Creating Loaded 24-ary Huffman Tree from data vector with char-symbols and int-weights;
* Creating Loaded Binary Huffman Tree from data vector with char-symbols and int-weights;
* Creating Dried (Unloaded) Binary Huffman Tree from data vector with int-weights (Fibonacci sequence);
* Creating Dried (Unloaded) Binary Huffman Tree from data file with int-weights;
* Creating Loaded Binary Huffman Tree from data file with char-symbols and int-weights;
* Creating Loaded Binary Huffman Tree from data vector with string-symbols and float-weights;
* Creating Loaded Binary Huffman Tree from data vector with AAA-symbols and BBB-weights;
* Encoding and Decoding vector-message using 5-ary Huffman Tree;
* Encoding and Decoding string-message using 5-ary Huffman Tree;
* Encoding and Decoding vector-message using Binary Huffman Tree;
* Encoding and Decoding string-message using Binary Huffman Tree



Source :
http://groups.google.com/groups?th=f9bb13f7426e888c

Raw run log (Demo) :
http://groups.google.com/groups?th=7daf90d4f66a47ad

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here