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 7984619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:20:00+00:00 2026-06-04T11:20:00+00:00

I am reading Huffman Coding Algorithm to encode a string. I can see that

  • 0

I am reading Huffman Coding Algorithm to encode a string. I can see that the frequency of the characters is taken into account to make a tree.

Here is the frequency table :

a   b   d   e   f   h   i   k   n   o   r   s   t   u   v 
5   1   3   7   3   1   1   1   4   1   5   1   2   1   1   9

*space has frequency 9

I can see there is a tree made with this. But I am not able to derive a rule how to place elements in tree.

The book says that all the characters with higher frequency should be near the root. But if more than two characters are of same frequency then they have to be on different sides of the root.

The question is, how do we decide the position?

IN my book a has the code 010, r has 011 and e has the code 100.

Can anyone please help?

  • 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-04T11:20:01+00:00Added an answer on June 4, 2026 at 11:20 am

    Have you tried Wikipedia? There’s a nice demonstration on Huffman coding. The algorithm is simple enough: you need a priority queue.

    The algorithm is somewhat like this:

    1. Create tree nodes with each character and their frequencies
    2. Put all the letters and their frequencies in a priority queue Q
    3. Do until Q contains only one element:
        3a. Pick two lowest-frequency items a, b
        3b. Create a tree node z with frequency(z) = frequency(a) + frequency(b)
        3c. Add a and b as left and right children of z
        3d. Put z in Q
    4. Pick up the only element from Q. This would be the root of the tree.
    5. Assign binary codes to each leaf node according to their root-to-leaf path.
    

    The priority queue should be designed as a min-priority queue, i.e. the node with lowest frequency should come out first. For handling equal-frequency items, use some other criteria (e.g. alphabetical order) as a tie-breaker. Be consistent with the tie-breaking criteria for both encoding and decoding.

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

Sidebar

Related Questions

Reading the code of many javascript libraries, I see that many developers use to
Reading through the CKEditor documentation , I see that they have an option to
reading the docs i see that the glGetTexImage2d() function has a 'type' parameter. The
Reading through the following instruction table manual I see that integer multiplication is often
Reading about the Dispose pattern , I see the documentation repeatedly refer to cleaning
reading the documentation for java org.w3c.dom.ls it seems as a Element only can be
i am trying to create a Huffman tree by reading in a file and
Reading source code of my current project, I see: [self retain] in one class,
Reading Chomsky hierarchy ... ... I know regexp can't parse type-2 grammars (context-free grammars),
Reading around Nokia forums, it seems that accessing the Cell ID and related information

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.