473,382 Members | 1,376 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,382 software developers and data experts.

How do I know if I am moving left or right in a binary tree?

Hey folks
I am implementing the Huffman encoding algorithm. I have created the
tree and its perfect.

Now while searching for a node value, I need to write a 0 to the
encoded file if I am moving left and 1 if I am moving right.

How will I know if I am moving left or right? For instance if I go to
the bottom of the left leaf and its leaflets and then come back and
find the value in one of the right leaves, I shouldnt be having all
those 00000s right?

Appreciate your ideas

Thanks
Crickie

Feb 21 '06 #1
1 1395
cr*********@yahoo.com wrote:
Hey folks
I am implementing the Huffman encoding algorithm. I have created the
tree and its perfect.

Now while searching for a node value, I need to write a 0 to the
encoded file if I am moving left and 1 if I am moving right.

How will I know if I am moving left or right? For instance if I go to
the bottom of the left leaf and its leaflets and then come back and
find the value in one of the right leaves, I shouldnt be having all
those 00000s right?

Appreciate your ideas

Thanks
Crickie


Despite your question is not c specific...

What did you put in your tree? What is it for?

Hufman's tree is useful to create table for encoding...
it's just a mean in order to create new alphabet from sorted alphabet

Having your tree, if leaves value is a character of your alphabet,
go left to right in order to produce your conversion's table...
just note you have turn left or right by shifting 1 or 0 in an int variable
code = (code << 1) & direction; /* 0 or 1 */
size_of_code++;
when you are in the leaf... you read the letter, associates the code
Be systematc..

Xavier
Feb 21 '06 #2

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

Similar topics

5
by: Ravi | last post by:
I recently had to write some code which required me to use a binary search tree (BST) due to running time concerns. I found that there is no BST class in the Standard C++ library. I have been told...
11
by: jova | last post by:
Is there a difference between a Binary Tree and a Binary Search Tree? If so can someone please explain. Thank You.
2
by: KalleD | last post by:
Why can I not move the windows taskbar with the SHAppBarMessage function? I am able to use the function for hiding it and other things, but not moving it (I have unchecked the lock). The code is...
9
by: sql guy123 | last post by:
I normally use MS ACCESS vs MS SQL,, which has a left() and right() function. I need to use MS SQL for this project but I am not familiar with it. I have read a few books, but can not figure out...
5
by: niklaus | last post by:
Hi, I have an array in which elements are present . The number of elements n <= 10^6 . Now if i delete an element in the array, i want to update the array by moving all the elements to the...
5
gekko3558
by: gekko3558 | last post by:
I am writing a simple binary search tree (nodes are int nodes) with a BSTNode class and a BST class. I have followed the instructions from my C++ book, and now I am trying to get a remove method...
8
by: n.noumia | last post by:
- with 10 nodes, give one example of an unbalanced binary tree and one example of a balanced binary tree - what is the advantage of having a balanced binary tree over an unbalanced tree? - number...
10
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE...
1
by: rsteph | last post by:
I bought a book to help me learn to use DirectX with windows programming. It's first trying to walk me through some basic windows programming and graphics before getting into DirectX. I'm trying to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.