Re: what type of tree algorithm is this?
- From: "James" <no@xxxxxxxxxxxx>
- Date: Wed, 11 Nov 2009 05:48:58 -0800
"Gene" <gene.ressler@xxxxxxxxx> wrote in message news:38b9873b-24bf-443b-92dc-e5106d2614a0@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Nov 11, 1:36 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
In <hdert2$nb...@xxxxxxxx>, James wrote:[...]
> I was not happy with a binary tree, so instead of comparing keys, I
> simply check of bits are set or not. Each bit represents a level in
> the tree, so if `unsigned long int' is 32-bit's then the tree will
> only have 32 levels
Sure sounds like a trie to me. (Not a typo, by the way: trIe.) They
have quite a few uses, but they are perhaps most famous for their
starring role in compression programs.
Take a look at this:
http://www.itl.nist.gov/div897/sqg/dads/HTML/trie.html
and see if it rings a bell.
It ends up looking like a trie, but it's slightly different from the
usual. This algorithm inserts based on the prefix (starting at the
lsb) that's sufficient to reach a missing node in the current tree.
The rest of the key is ignored. So insertion order matters.
Right. This modified "trie" is not sorted when you traverse it like:
void traverse(struce tree* t)
{
if (t)
{
traverse(t->left);
printf("%lu\n", t->key);
traverse(t->right);
}
}
It just that I did not need to process anything in any particular order, so this "hacked" trie seems to be working pretty darn good for my application so far.
A
classical trie would, I suppose, create N levels where the MSB of the
key is at bit N-1, and insertion order would be immaterial. It's a
small change, but it's a pretty clever idea for the OP's application,
which seems to be a hash table for unsigned ints.
Yeah. I was experimenting with the hash to try and take "pressure" off of a single trie. With the hash in place I guess the complexity would be something like:
let N = total bits in key
no collision
--------------------------------------------------------
O(1) - best-case
collision
--------------------------------------------------------
O(log N) - worst-case
collision on a trie with N levels and item is at level N
--------------------------------------------------------
O(N) - horrible-case
Who knows, this hack might be fairly useful to somebody else besides me!
;^)
.
- References:
- what type of tree algorithm is this?
- From: James
- Re: what type of tree algorithm is this?
- From: Richard Heathfield
- Re: what type of tree algorithm is this?
- From: Gene
- what type of tree algorithm is this?
- Prev by Date: Re: How to choose a Data-Structure for a Priority Queue ?
- Next by Date: Re: How to choose a Data-Structure for a Priority Queue ?
- Previous by thread: Re: what type of tree algorithm is this?
- Next by thread: Re: what type of tree algorithm is this?
- Index(es):
Relevant Pages
|