473,503 Members | 10,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to do a lookup tree

Suppose you have a binary tree structure, full of some values, and you
have to use the tree to lookup something based on values from a
bitstream (ie. take the left branch if the bit is zero, the right if
the bit is one, that kind of thing). The values in the tree, as well
as the general layout, is hardcoded.

I've been thinking about various ways, from multidimensional arrays to
"static initializer functions". What do you think would be the best
way to implement it?

--
I am only a mirage.
Mar 6 '06 #1
3 2037
* kelvSYC:
Suppose you have a binary tree structure, full of some values, and you
have to use the tree to lookup something based on values from a
bitstream (ie. take the left branch if the bit is zero, the right if
the bit is one, that kind of thing). The values in the tree, as well
as the general layout, is hardcoded.

I've been thinking about various ways, from multidimensional arrays to
"static initializer functions". What do you think would be the best
way to implement it?


Define "best", in a manner that allows clear-cut selection from
different solutions.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 6 '06 #2
kelvSYC wrote:
Suppose you have a binary tree structure, full of some values, and you
have to use the tree to lookup something based on values from a
bitstream (ie. take the left branch if the bit is zero, the right if
the bit is one, that kind of thing). The values in the tree, as well
as the general layout, is hardcoded.

I've been thinking about various ways, from multidimensional arrays to
"static initializer functions". What do you think would be the best
way to implement it?


The best way to implement the program is in whichever way that I (were
I the programmer) find it easiest to understand. And I would only ever
depart from my original design in the event that other issues (such as
suboptimal performance measurements) gave me an good enough reason to
change it.

So if the purpose of the program is to walk down a binary tree, using a
bit stream to select which branch to follow at each step, then that is
exactly the way that I would code it - because that is exactly how you
explained what the program is supposed to do.

Not one of the most sophisticated algorithms, data structures, or
programming techniques is worth anything at all, if the program fails
to deliver the correct results. So write correct code first, and think
about optimizations (should they even be needed) afterwards.

Greg

Mar 6 '06 #3

kelvSYC wrote:
Suppose you have a binary tree structure, full of some values, and you
have to use the tree to lookup something based on values from a
bitstream (ie. take the left branch if the bit is zero, the right if
the bit is one, that kind of thing). The values in the tree, as well
as the general layout, is hardcoded.

I've been thinking about various ways, from multidimensional arrays to
"static initializer functions". What do you think would be the best
way to implement it?

--
I am only a mirage.


Look up extendible hashing. It sort of uses a tree like impementation
and fits what you are describing.

Mar 6 '06 #4

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

Similar topics

3
1945
by: Mike Conmackie | last post by:
Greetings, I am trying to create a node in the output tree using a variable. Here are some fragments that I hope will explain the problem better. <xsl:stylesheet...
12
6954
by: pillepop2003 | last post by:
Hey! Can anyone give me a hint, how this problem is best implemented: I have a table of users (see below), where every user has one "superior user" (= parent node), this should be a fully...
6
1495
by: m.barenco | last post by:
Hello, I am considering using dictionnaries as lookup tables e.g. >>>D={0.5:3.9,1.5:4.2,6.5:3} and I would like to have a dictionnary method returning the key and item of the dictionnary...
19
6744
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
9
6290
by: GiantCranesInDublin | last post by:
Hi, I am looking for the best performing solution for modifying and iterating an object graph in JavaScript. I have outlined below a simplified example of the object model and examples of how I...
4
4927
by: Mitchel Haas | last post by:
Hello, Feeling a need for a generic tree container to supplement the available containers in the STL, I've created a generic tree container library (TCL). The library usage is very much like...
17
3008
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
13
5572
by: paul.joseph.davis | last post by:
Hi, I've just had my first encounter with two-phase lookup and I'm scratching my head a bit. The idea behind two phase look up is pretty easy to understand, but I have a case that fails to...
6
4073
by: pj | last post by:
Hi, I 'm currently writing a program that performs transliteration (i.e., converts greek text written using the english alphabet to "pure" greek text using the greek alphabet) as part of my...
0
7207
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
7095
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
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.