algorithmdata-structureshashtabletrie

How Do I Choose Between a Hash Table and a Trie (Prefix Tree)?


So if I have to choose between a hash table or a prefix tree what are the discriminating factors that would lead me to choose one over the other. From my own naive point of view it seems as though using a trie has some extra overhead since it isn't stored as an array but that in terms of run time (assuming the longest key is the longest english word) it can be essentially O(1) (in relation to the upper bound). Maybe the longest english word is 50 characters?

Hash tables are instant look up once you get the index. Hashing the key to get the index however seems like it could easily take near 50 steps.

Can someone provide me a more experienced perspective on this? Thanks!


Solution

  • Advantages of tries:

    The basics:

    New operations:

    Advantages of linked structure:

    Advantages of hashtables: