Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:38:44+00:00 2026-06-16T00:38:44+00:00

I have written a program to encoded a article to huffman code and output

  • 0

I have written a program to encoded a article to huffman code and output a code table.

H:000
d:1011
e:100
l:11
o:01
r:1010
w:001
Total bits:27
Encoded code:000100111101001011010111011

and I want to write a program which take the file as input and to decode it.

But I have no idea how to rebuild it.

My question is how to rebulid the huffman tree?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:38:44+00:00Added an answer on June 16, 2026 at 12:38 am

    You don’t need to rebuild the Huffman tree if the code has been constructed in a canonical manner, which makes the shorter codes numerically smaller than the longer codes. There are many ways to arbitrarily assign the 0 and 1 to each branch of a Huffman binary tree, and all result in the same optimality of the code. Picking one of the many choices provides advantages in decoding and in conveying the code.

    The only information needed from the Huffman algorithm is the code lengths, i.e. the number of bits for each symbol. With that, you can construct a canonical Huffman code advancing from the shorter codes to the longer codes, and sorting the symbols in lexical order within any given code length (e.g. sort all the length 3 codes in the order H, e, w). The point of sorting within a code length is to reduce the amount of data to be sent to the receiver in order to reconstruct the code.

    You then arrive at this alternative code:

    l:00
    o:01
    H:100
    e:101
    w:110
    d:1110
    r:1111
    

    Now decoding can be done with a two simple tables, one which is just those symbols in order, i.e. “loHewdr”, and the code values at which you step up to the next code length. The steps are 0000 from one to two bits, 1000 to three bits, 1110 to four bits. You read in enough bits for the longest code (append zeros if needed at the end, but don’t use those as the start of a code in a subsequent step). Then if the value is less than the value of the start of the next code length, use that value as the index into the table, taking into account the current number of bits in the code. Otherwise add the number of values up to that next value to the index, and check the next step. Calculating the number of values skipped requires also keeping track of the number of bits in the code in the current step.

    Once you decode a symbol, you know how many bits it was. Remove those bits from the stream and repeat.

    This approach also has the advantage of being the fastest for the shortest codes, which are the most common. The resulting decoding speed is very good. (There are other table-driven methods that are faster, but they are much more complicated.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a MapReduce program, code is below: import java.io.IOException; import java.util.Iterator; import
I have written a program which analyzes a project's source code and reports various
I have written PLSQL program that generates table having usually more than 200 columns.
I have written a program in c++ to output the number in the fibonacci
I have written a program that consists of roughly 3000 lines of code. The
I have written a program in Python that generates a 10,000 tile coordinate plane
I have written a program for Bar code scanner application it works fine in
I have written php program and uploaded on server. I want run this program
I have written a program in VB6. When I compile it and send it
I have written a program that uses qhttp to get a webpage. This works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.