Aguri: Coolest Data Structure You've Never Heard Of
matasano.com
matasano.com
Also confused how he proposes to build his Radix Trie in less than linear time... just seems like he ditches his original premise and launches into routing. There are selection algorithms that will find things in an unsorted array in O(lg(n))... but pretty sure building a tree of any sort is not part of it.
Radix Tries are sweet fun... so is just good old Radix Sort, but he starts with something that doesn't really make sense for the topic (the unsorted array he wants to pull three out of), then makes some weird claims, then jumps into routing with Radix Tries... not sure what is insightful here.
You're like the 4th person I've seen that read (some) of this article and pulled this tree vs. hash thing out of it. It's a throwaway point. Binary trees provide comparable performance to hash tables, but also provide efficient access to ranges of keys. Binary trees support more operations efficiently than hash tables.
The article isn't about some war I've declared on hash tables.
For average lookup time, which is a reasonable context to assume in the preceding comment, yes they are.
With a good hash function (collision resistant), the amortized cost of lookup is O(1), even if you need to resize the table.
If you had read more than (some) of my comment you might have gathered that was my entire point. The first page of your post was a throwaway point... nothing to do with your actual point, which seemed to be Radix Tries. It would've been nice to dispense with the distraction was all I was saying.
I know that given a lot of collisions that hash tables degenerate into linear insertion and lookup... and I did point out that binary trees are better for several things, but I still maintain that you can't just outright claim one is better than the other for every situation.
Oh, and as for failing the job interview... not really sure why that was necessary. You don't make a stronger point by being a dick about it.
tptacek, what do you think they are?
Worst case search for a radix trie is always O(k); radix tries don't require balancing.
Where did you go to school?
Where I went to school, we were taught not to compare the worst case behavior of one structure to the average of another. We were also taught not to confuse binary trees with red-black trees.
Agreed. However the original poster said binary tree, a specific structure whose worse case behavior is O(n) just like a hash table.
They didn't say binary search tree (which as you observe may refer to one of several possible structures).
(1) you need fast lookup and fast inserts
(2) you need to preserve the lexicograhpic order of your elements - something that a hash table won't give you
(3) you are afraid of DoS attacks or maybe just "bad" data - hash tables can be attacked easily if the implementation is known
(4) you don't care about memory usage that much.
I compared a simple 8-bit radix tree with some standard hash table implementation - the former took roughly ten times more memory. I then changed my radix to be based on 4 bits (each char is just split into 2 parts) and the memory usage improved twice. Now I'm wondering if radix tries have more room for improvement.
So this is something to consider.
And thanks for the article - never heard of Aguri, it's beautiful.
Upd. sorted lists basically give you same advantages except for fast inserts
Since hash tables by necessity have to allocate enough storage to keep table load down and minimize collisions, you could find a PATRICIA tree has even better memory footprint than whatever hash table you use.
Of course, all data structures share the DoS problem. There's an input to a PATRICIA tree that pessimizes lookup and memory usage: the one that creates a full 32 bits of fanout for every key. In all cases, the attack degrades performance to linear search.
Of all the "mainstream" data structures, balanced binary trees are probably the hardest to attack this way.
Of course I used compressed suffixes, but it didn't help much as compared with hash tables.
you could find a PATRICIA tree has even better memory footprint than whatever hash table you use
I don't think you can demonstrate that Patricia has a better memory footprint than a good hashtable. In fact best radix trees are much worse.
Of course, all data structures share the DoS problem.
You can attack radix trees in terms of memory usage, while hash tables are prone to serious performance attacks.
In all cases, the attack degrades performance to linear search.
Not true. I don't think you understand these algorithms and O(n) complexity very well.
The question how a hash table degrades when attacked highly depends on how exactly conflict resolution is implemented. Among other methods is, for example, expansion and rehashing, and you can't tell for sure if it degrades to linear search or not.
And radix never degrades to linear search - never.
Of all the "mainstream" data structures, balanced binary trees are probably the hardest to attack this way.
They are prone to a very specific attack when you make the tree to re-balance often.
I believe I don't ignore anything, I'm measuring precise memory usage by two identical programs doing same thing but based on different algorithms. I also believe I got the most out of radix in my tests. The 4-bit version of radix wasn't trivial, but it was reasonably fast and the mem usage was twice as better than the 8-bit one, as I said before.
But even speculatively, on paper if you wish, radix consumes more memory than some good hash table implementation.
Upd. forgot to mention, I did some more optimizations as well, like compressing the pointer tables in tree nodes.
One of the coolest compression algorithms evar...
An interesting first step.