LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-16-2015, 08:22 AM   #1
atlantis43
Member
 
Registered: Feb 2013
Posts: 289

Rep: Reputation: Disabled
Huffman tree encoding question


Given a Huffman Tree with struct trees composed of (only) the following members:
Code:
typedef struct tree
{
    char symbol;
    int frequency;
    struct tree* left;
    struct tree* right;
}
Tree;
I'm wondering about the process of traversing such a tree to obtain the encoding values.
I assume that as each leaf of this tree is encoded, it would then be necessary to remove it from the tree so as not to repeat traversal of the same leaf.
Is my assumption correct, or is there another way (without including member-data such as the 'level' of the node) to go about such a process?
Thanks for any help.
 
Old 05-16-2015, 10:37 AM   #2
SoftSprocket
Member
 
Registered: Nov 2014
Posts: 399

Rep: Reputation: Disabled
Generally when you traverse a tree you follow a pattern and that is how you know where to go. Another method is to maintain a stack that holds next information as required.

For a binary tree The Art of Computer Programming gives the traversal patterns listed here: http://webdocs.cs.ualberta.ca/~holte...traversal.html
Another look at it: http://www.geeksforgeeks.org/618/
 
1 members found this post helpful.
Old 05-16-2015, 11:07 AM   #3
atlantis43
Member
 
Registered: Feb 2013
Posts: 289

Original Poster
Rep: Reputation: Disabled
thanks for nice concise link which explains the process.
 
Old 05-18-2015, 08:28 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
Exactly, the purpose of a Huffman tree is to allow you to efficiently obtain the shortest-possible bit vector that can encode that particular character. It is a remarkably elegant solution to a problem that was once regarded as intractable.
 
1 members found this post helpful.
Old 05-19-2015, 12:24 PM   #5
atlantis43
Member
 
Registered: Feb 2013
Posts: 289

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
Exactly, the purpose of a Huffman tree is to allow you to efficiently obtain the shortest-possible bit vector that can encode that particular character. It is a remarkably elegant solution to a problem that was once regarded as intractable.
Still haven't figured out suitable recursive code for writing the 0's & 1's, but sooner or later I'll get it. Trying to modify some code for 'printing paths' for success.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux MP3 Encoding Question eQuinas Programming 3 04-19-2008 10:25 AM
file tree question chokeX Linux - Newbie 1 11-03-2005 08:12 PM
School project : reproducing huffman networking compression gusx Linux - Networking 1 09-19-2005 09:25 PM
easy video encoding question mynameisflorian Linux - Software 8 08-17-2005 04:57 PM
huffman algorithm mcshen Programming 3 03-12-2004 02:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration