Complexity in using Binary search and Trie

Posted by user121196 on Stack Overflow See other posts from Stack Overflow or by user121196
Published on 2010-04-27T04:51:49Z Indexed on 2010/04/27 5:03 UTC
Read the original article Hit count: 198

given a large list of alphabetically sorted words in a file,I need to write a program that, given a word x, determines if x is in the list. Preprocessing is ok since I will be calling this function many times over different inputs.
priorties: 1. speed. 2. memory

I already know I can use (n is number of words, m is average length of the words) 1. a trie, time is O(log(n)), space(best case) is O(log(n*m)), space(worst case) is O(n*m).
2. load the complete list into memory, then binary search, time is O(log(n)), space is O(n*m)

I'm not sure about the complexity on tri, please correct me if they are wrong. Also are there other good approaches?

© Stack Overflow or respective owner

Related posts about data-structures

Related posts about algorithms