Search code examples
javaalgorithmdata-structuressearch-engine

how to search for a given word from a huge database?


What's the most efficient method to search for a word from a dictionary database. I searched for the answer and people had suggested to use trie data structure. But the strategy for creating the tree for a huge amount of words would be to load the primary memory. I am trying to make an android app which involves this implementation for my data structure project. So could anyone tell me how do the dictionary work.

Even when I use the t9 dictionary in my phone, the suggestions for words appear very quickly on the screen. Curious to know the algorithm and the design behind it.


Solution

  • You can use Trie which is most usefull for searching big dictionaries. Because too many words are using similar startup, trie brgins around constant factor search also you can use in place, with limited number of access to physical memory. You can find lots of implementation in the web.

    If someone is not familiar with trie, I think this site is good and I'm just quoting their sample here:

    A trie (from retrieval), is a multi-way tree structure useful for storing strings over an alphabet. It has been used to store large dictionaries of English (say) words in spelling-checking programs and in natural-language "understanding" programs. Given the data:

    an, ant, all, allot, alloy, aloe, are, ate, be 
    

    the corresponding trie would be: Sample Trie for above words

    This is good practical Trie implementation in java: http://code.google.com/p/google-collections/issues/detail?id=5