Doubt related huffman

it is giving wrong output ,please check ,it is Huffman code.




and can you explain the difference between getValue ()and get () function because both are returning the values ?

Hey @Mansi,

Can you compile the code in one file and send me the link.

Also, the difference between, GetValue and Get is that, the getValue method is used to fetch the value of the object from the index passed as the parameter.
We use get method to fetch the value mapped by a particular key mentioned in the parameter in a HashMap. Get method will return NULL if no such mapping is found for any key you pass.

can you please tell me how to do it in one file

Hi @Mansi,
I have made certain changes in your code and put it in 1 file. https://ide.codingblocks.com/s/148442
Also, you didn’t define the return type of huffman method. You huffman tree will look like the following:
D - 1
C- 01
B - 001
A - 000

Here’s how the Huffman Tree will look like with this, this takes 17 bits:

Now the problem I believe, is with the min heap. Because, in an ideal scenario the huffman tree should be like this, as this takes up 14 bits compared to 17 bits of the last approach. :

i have define huffman as constructor not as method

Hi @Mansi,
In my code, huffman is working fine. There is a problem with the min heap. Because I gave you the ideal scenario and the output your code is giving.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.