473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

encoding tree

I wanted to write a simple huff tree table that would take a basic list
of frequenccy table and return the code for each character.

Say input would be:

//"print this out." is what the this table represents
10 1
32 2
46 1
104 1
105 2
110 1
111 1
112 1
114 1
115 1
116 3
117 1

The program will then convert to the code for each character and it
would look like the follwing:

117 000
32 001
105 010
10 0110
46 0111
104 1000
110 1001
111 1010
112 1011
114 1100
115 1101
116 111
If anyone has any ideas on how to start or how to make it read the list
from stdin and start this process that would be great.

Apr 25 '06 #1
7 1936
tonokio wrote:
I wanted to write a simple huff tree table that would take a basic
list of frequenccy table and return the code for each character.

Say input would be:

//"print this out." is what the this table represents
10 1
32 2
46 1
104 1
105 2
110 1
111 1
112 1
114 1
115 1
116 3
117 1

The program will then convert to the code for each character and it
would look like the follwing:

117 000
32 001
105 010
10 0110
46 0111
104 1000
110 1001
111 1010
112 1011
114 1100
115 1101
116 111
If anyone has any ideas on how to start or how to make it read the
list from stdin and start this process that would be great.


Start like this:

#include <iostream>
int main()
{
while (!std::cin.eof())
{
// read what you need, using operator >> or 'getline'.
// act upon what you just read
}
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 25 '06 #2
"tonokio" writes:
I wanted to write a simple huff tree table that would take a basic list
of frequenccy table and return the code for each character.

Say input would be:

//"print this out." is what the this table represents
10 1
32 2
46 1
104 1
105 2
110 1
111 1
112 1
114 1
115 1
116 3
117 1

The program will then convert to the code for each character and it
would look like the follwing:

117 000
32 001
105 010
10 0110
46 0111
104 1000
110 1001
111 1010
112 1011
114 1100
115 1101
116 111
If anyone has any ideas on how to start or how to make it read the list
from stdin and start this process that would be great.


I will take a wild guess that huff is street talk for Huffman. I had no
idea he had entered the popular culture; how very trendy. If my guess is
right, there are two parts to the problem.

o Construct a table containing the frequency of the various characters in
the alphabet.
o Using that table, contract a table of suitable codes.

There are several tutorials on the web WRT bullet 2 that are probably better
than anything someone is going to write in a few minutes and post here.

If your problem is with bullet 1, say so.
Apr 25 '06 #3
Yes, I have a problem with bullet 1 which is to Construct a table
containing the frequency of the various characters in the alphabet.

osmium wrote:
"tonokio" writes:
I wanted to write a simple huff tree table that would take a basic list
of frequenccy table and return the code for each character.

Say input would be:

//"print this out." is what the this table represents
10 1
32 2
46 1
104 1
105 2
110 1
111 1
112 1
114 1
115 1
116 3
117 1

The program will then convert to the code for each character and it
would look like the follwing:

117 000
32 001
105 010
10 0110
46 0111
104 1000
110 1001
111 1010
112 1011
114 1100
115 1101
116 111
If anyone has any ideas on how to start or how to make it read the list
from stdin and start this process that would be great.


I will take a wild guess that huff is street talk for Huffman. I had no
idea he had entered the popular culture; how very trendy. If my guess is
right, there are two parts to the problem.

o Construct a table containing the frequency of the various characters in
the alphabet.
o Using that table, contract a table of suitable codes.

There are several tutorials on the web WRT bullet 2 that are probably better
than anything someone is going to write in a few minutes and post here.

If your problem is with bullet 1, say so.


Apr 25 '06 #4
Victor Bazarov wrote:
tonokio wrote:
I wanted to write a simple huff tree table that would take a basic
list of frequenccy table and return the code for each character.

Say input would be:

//"print this out." is what the this table represents
10 1
32 2
46 1
104 1
105 2
110 1
111 1
112 1
114 1
115 1
116 3
117 1

The program will then convert to the code for each character and it
would look like the follwing:

117 000
32 001
105 010
10 0110
46 0111
104 1000
110 1001
111 1010
112 1011
114 1100
115 1101
116 111
If anyone has any ideas on how to start or how to make it read the
list from stdin and start this process that would be great.


Start like this:

#include <iostream>
int main()
{
while (!std::cin.eof())
{
// read what you need, using operator >> or 'getline'.
// act upon what you just read
}
}


Victor, I'm surprised at you! You know that that the "while not eof"
idiom gives an extra spurious read.

#include <iostream>

int main()
{
int value;
int frequency;

while (std::cin >> value >> frequency)
{
// do something with your value and frequency
}

}
Apr 25 '06 #5
I did some reading online and I realize there is more than one way to
implement this huffman tree and even more suprising it doesn't require
an advanced data structure, I think it was purposed somewhere that even
that is not necessary. I don' think we're suppose to use an ADT, just
something simple to encode to the huffman codes. I think a BST would be
easy to use, but I want to see if there is something that could be
simpler and more straight forward, least in the coding sense. I'm only
given input files that are already in a frequency list format as the
beginning post stated.

Apr 25 '06 #6
My program already generates the frequency list and I was wondering how
would we read int he first and second column and store it into an
array?

#include <iostream>

int main()
{
int value; //perhaps make this into an array
int frequency; //perhaaps make this into an array

while (std::cin >> value >> frequency)
{
// do something with your value and frequency
}
}

the file that I will redirect in to the huffman program will look like:
//char //freq
102 4
117 29
..
..
..

I wanted to know how to parse it in stdin and store them into an array
before I generate a min-heap and insert the values to make the huffman
tree.

tonokio wrote:
I did some reading online and I realize there is more than one way to
implement this huffman tree and even more suprising it doesn't require
an advanced data structure, I think it was purposed somewhere that even
that is not necessary. I don' think we're suppose to use an ADT, just
something simple to encode to the huffman codes. I think a BST would be
easy to use, but I want to see if there is something that could be
simpler and more straight forward, least in the coding sense. I'm only
given input files that are already in a frequency list format as the
beginning post stated.


Apr 26 '06 #7
I got some of the program working and when I generate the huff code I
still get some descrepency and I was wondering if anyone could see if
there is anything wrong with my logic.
http://cpp.sourceforge.net/?show=15272

We were given a test app to use our code and the enc/dec part of the
program hasn't been written but I tested my program so far with the
code that I generate and an input and the output does not match when it
is enc/dec with my codes. Thank you for your time.
tonokio wrote:
My program already generates the frequency list and I was wondering how
would we read int he first and second column and store it into an
array?

#include <iostream>

int main()
{
int value; //perhaps make this into an array
int frequency; //perhaaps make this into an array

while (std::cin >> value >> frequency)
{
// do something with your value and frequency
}
}

the file that I will redirect in to the huffman program will look like:
//char //freq
102 4
117 29
.
.
.

I wanted to know how to parse it in stdin and store them into an array
before I generate a min-heap and insert the values to make the huffman
tree.

tonokio wrote:
I did some reading online and I realize there is more than one way to
implement this huffman tree and even more suprising it doesn't require
an advanced data structure, I think it was purposed somewhere that even
that is not necessary. I don' think we're suppose to use an ADT, just
something simple to encode to the huffman codes. I think a BST would be
easy to use, but I want to see if there is something that could be
simpler and more straight forward, least in the coding sense. I'm only
given input files that are already in a frequency list format as the
beginning post stated.


May 1 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rutger Claes | last post by:
I have a dom tree representing the content of a html document. In the xml I use &#x20AC; as the euro sign. I think I need to do this to be able to use xsl transformations. After the xsl...
1
by: Mike | last post by:
Code : xmlParserCtxtPtr ctx; sax_handler.startElement = startElement; sax_handler.characters = characters; sax_handler.endElement = endElement; sax_handler.getEntity = getEntity; ...
2
by: Lionel Fourquaux | last post by:
In .Net 1.1, System.Xml.Xsl.XslTransform cannot output directly a document in an encoding that cannot represent all the characters used (e.g. write in us-ascii for compatibility, and convert all...
0
by: icoba | last post by:
Hi, I am parsing html documents using the html parser from libxml2, and if the encoding is included in the document it works perfectly but if it is not, I think it does not work well (probably...
0
by: Chris McDonough | last post by:
ElementTree's XML serialization routine implied by tree._write(file, node, encoding, namespaces looks like this (elided): def _write(self, file, node, encoding, namespaces): # write XML to file...
15
by: Steven Bethard | last post by:
I'm having trouble using elementtree with an XML file that has some gbk-encoded text. (I can't read Chinese, so I'm taking their word for it that it's gbk-encoded.) I always have trouble with...
3
by: mortb | last post by:
1. How do I determine which encoding a xmldocument or xmlreader uses when opening a document? I'm not just talking about the <?xml encoding="utf-8"?attribute, but the actual encoding of the...
11
by: KWSW | last post by:
The other thread got too long so decided to start a new one. Got my huffman tree working and am now moving onto encoding and decoding my given text file. My idea now is to print out all the leaf...
0
by: coucchy | last post by:
Hello everyone, i'm writing a C program that will read a text file and then encode the characters using huffman algorithm. So far i've read the files, built a tree, and now I'm building the strings...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.