given the large list of alphabetically sorted words in the file, I need to write a program that, given the word x, determines if x is in the list. The preprocessing is fine, as I will call this function many times on different inputs.
priorties: 1. speed. 2. memory
I already know that I can use (n is the number of words, m is the average word length) 1. trie, time O (log (n)), space (best case) - O (log (nm)), space (worst case ) - O (nm).
2. Load the complete list into memory, then binary search, time O (log (n)), space O (n * m)
I'm not sure about the complexity on tri, please correct me if they are wrong. Also have other good approaches?
algorithm complexity-theory data-structures
user121196 Apr 27 '10 at 4:51
source share