CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Huffman code

  1. #1
    Join Date
    Jan 2004
    Location
    New York
    Posts
    27

    Huffman code

    Does anyone know how to implement a binary tree with Huffman codes?

  2. #2
    Join Date
    Feb 2002
    Posts
    5,757
    Tell me about Huffman's algorithm.

    Kuphryn

  3. #3
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    Huffman's alogorithm looks like this:

    A) Start with as many trees as there are symbols.
    B) While there is more than one tree:

    1. Find the two trees with the smallest total weight.
    2. Combine the trees into one, setting one as the left child and the other as the right.

    C) Now the tree contains all the symbols. A '0' represents following the left child; a '1' represents following the right child.

    All you need is a function, which calculates the weight of your symbols - e.g., if you are using a text, this would be the frequency with which single letters appear!
    The Saviour of the World is a Penguin and Linus Torvalds is his Prophet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured