binary search and trio
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
4:53 UTC
Read the original article
Hit count: 356
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. 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 tri, 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