DEV Community

Discussion on: Trie - Data Structure & Algorithm Part VI

fernandoblima profile image
Fernando Baptistella Author

Thanks for your comment! After reading it, I believe I was misunderstood because I did not explain it correctly.

I’ll try to improve the implementation of this code and see the effect when the number of items is increasing, but, as I said, my code was just a simple example of trie structure. And it is necessary to consider that the native associative array/hash of the javascript will have better results because already have a nice well-optimized implementation. That said, the array will be more faster than most general purposes.

I agree with you when you said that the trie isn't an O(1) as a hash-table... But the trie can perform better in some complex problems, such as a search engine or autocomplete feature comparing with the hash table structure. Because we have to consider an imperfect associative array and it's almost impossible to create a uniform random distribution to avoid conflicts that lead to handling collisions by separate chaining or linear/double/Quadratic Proibing, the time to calculate the hash table, memory accesses...

I did't understand the problem in your project, but if you want, you can describe more and I can try to help you :)