Results 1 to 1 of 1
Thread: Help: traversing huffman tree
- 05-24-2011, 09:42 AM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
Help: traversing huffman tree
Hello,
I have been doing a project of Huffman encoding/decoding.
The program receives input, counts the character frequency, then makes the Huffman tree.
After I build the tree, I don't know how to traverse all the tree from the root to every leaf to make the code table.
for example, let's consider this input: "SUSIE SAYS IT IS EASY"
frequency table:
Character freq
A 2
E 2
I 3
S 6
T 1
U 1
Y 2
Space 4
Linefeed 1
Huffman tree: sp: space; lf: line feed; * means no character
-----------------------*, 22----------------------
-----*, 9------- -----*, 13----
sp, 4 ----*, 5--------- S, 6 ----- *, 7------
A, 2 ------*, 3------ I, 3 -----*, 4----
T, 1 -----*, 2---- Y, 2 E, 2
lf, 1 U, 1
Now, I need to traverse all the tree from the root to every leaf to make the code table. When turn left, '0' will be recorded and '1' for turning right. It means I must have the code table like:
Character Code
A 010
E 1111
I 110
S 10
T 0110
U 01111
Y 1110
Space 00
Linefeed 01110
The problem is, I don't know how to write the code to traverse the tree.
Do you guys have any idea?
Similar Threads
-
Huffman encoding/decoding
By warlock in forum New To JavaReplies: 4Last Post: 04-05-2011, 06:59 AM -
Methods in FrequencyTree (or Huffman Tree?)
By Beginner101 in forum EclipseReplies: 0Last Post: 04-04-2011, 09:31 PM -
CHALLENGING: Huffman coding
By nadissen in forum EclipseReplies: 0Last Post: 03-29-2011, 09:05 PM -
huffman coding in java
By warlock in forum New To JavaReplies: 2Last Post: 03-12-2011, 12:59 PM -
How do I write bits to a file( for Huffman Tree compressing)
By ryuzog in forum New To JavaReplies: 2Last Post: 10-28-2010, 10:45 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks