Thursday, December 15, 2011

Binary tree question... More of a misunderstanding of how they work.?

I understand how they speed up sort times. What I don't understand is how to implement them with multiple variables. If I have the Tree setup to sort the names how does it help when I want to sort on city, or state, or some other type of information?


Would I make a tree for each type of information?


When dealing with records with various amounts of information, how do binary trees come in to play is my real question?|||You would create a tree for each type of information you wanted to search/sort on. This is (at a rudimentary level) the same as creating an index in SQL for the different data queries you expect to make.





In situations where you want to sort on multiple values all at once, you would either combine all the values you want to use into a single value which could then be used as a single key or create separate sub-trees for each deeper value.





When using multiple values, search order becomes very important and depending on your algorithms you can run into some pretty hefty roadblocks with complex data designs. Although it's worth it to understand how a binary tree works, I highly recommend not trying to reinvent the wheel for any complex data tree. Find and use the methods that are available through the software you are using, or add/implement public domain code.|||What i've understood through your question is that u want to store multiple names in a single tree. Its so simple, Make the node of the tree with as many data containers as you want.


the basic structure would be


class node


{


int *right; // Address of right leaf


int *left; // address of left leaf


char *city; // your datum


char *state; // your datum


char *XYZ; // your datum


}|||I would suppose that non-numeric data is hashed somehow. It's the same way that String keys are hashed into numeric indices using bit manipulation, prime numbers, modulo arithmetic, etc. Then you can combine these hashed numbers.

No comments:

Post a Comment