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

  • SEARCH
  • Home
  • 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 8932807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:23:33+00:00 2026-06-15T09:23:33+00:00

I am writing a code that takes a word such as abracadabra and make

  • 0

I am writing a code that takes a word such as “abracadabra” and make it into a huffman tree. I understand the principles of the Huffman tree, but what I am snagged up on right now is how I am going to first implement abracadabra into it.

The approach that my teacher has told us to go is to have two separate queues/arrays. The first stores the amount for each letter, and the other stores the letters in order of the amount (highest to lowest) and when letters have the same value they are sorted alphabetically.

So it would result in: 5,2,2,1,1 and a,b,r,c,d
I am fairly sure he wants us to use a queue, but I do not know how to approach this simple part of the code..

Any help would be most grateful.

  • 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-15T09:23:34+00:00Added an answer on June 15, 2026 at 9:23 am

    I can’t think why you’re being asked to write it in quite that form, but off the top of my head, I’d do this:

    Initialise your two queues for counts and letters.
    
    For each letter in the input:
     Search for letter in letter-queue.
     If found
       set count to the corresponding value from the count-queue + 1
       remove from both queues
     Else
       set count to 1
     Add the letter and count into both queues in the correct place
    

    When you’re done, you have a queue in the right order for building your tree.

    Feels like an abuse of a queue to me, but if that’s what you were asked to do…

    Edit: Here’s how I’d probably actually write it, without queues etc.

    unsigned char input[]="abracadabra";
    int counts[256];
    memset(counts, 0, 256 * sizeof(int));
    
    unsigned char i;
    unsigned char *pt = input;
    int max = 0;
    while(i = *pt++)
    {
        counts[i]++;
        if(counts[i] > max) max = counts[i];
    }
    
    while(max)
    {
        int nmax = 0;
        for(int c = 0 ; c < 256 ; c++)
        {
            if(counts[c] < max && counts[c] > nmax) nmax = counts[c];
            if(counts[c] == max)
            {
                printf("%c: %d\n", c, max);
            }
        }
        max = nmax;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some code that takes a report from the mainframe and converts it
I am a very proficient C# developer, but need to start writing code that
I'm writing code that takes a number from a user and prints in back
I'm writing a piece of client-side javascript code that takes a function and finds
So essentially I find myself writing a bunch of boiler plate code that takes
I am writing a code that I am sure is very simple, but for
I am writing some code that takes a LINQ to SQL IQueryable<T> and adds
I'm writing a php script that takes some c code and tests it against
I'm writing some code that takes a filename, opens the file, and parses out
so I'm writing code that takes a pathname , a signature , and the

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.