10 ms·
While a Trie is the "correct" datastructure with appropriate storage techniques, you have to be careful when your hands are tied regarding what datastructure yo
by shazow 16y ago
While a Trie is the "correct" datastructure with appropriate storage techniques, you have to be careful when your hands are tied regarding what datastructure you build it on top of.
When I benchmarked a Trie implementation using dicts of dicts in Python, and I found that the memory usage was an order of magnitude higher than just having a set or list of strings (2mb vs ~100kb), while the performance difference was negligible. I ended up going with a set.
The issue is that each layer per node has 26+ instances of your core object struct (whether it's a list or a dict), so any overhead gets ballooned really fast.
- wisty 16y agoYou can get around that by using an array, and having functions to get and set parts of the array. That stops the object overhead in python from killing memory. But it's not the prettiest way to do things.