On Tue, Dec 20, 2011 at 1:27 AM, Jim Graham <[email protected]> wrote: > On Mon, Dec 19, 2011 at 09:26:11PM -0800, felix wrote: >> Hi! >> I'm working on a dict app on android, >> I need to search a list of words(about 500-600 thousand words) in file >> to find the word. >> It took me about 10-20 seconds to search the word. How can I improve >> the search speed? > > Well, along with Kris's solutions, here's another (that you could use > with his, or on its own if it's enough): > > Use whatever works best for you (regexp or simply grabbing the first > char directly from the string) and get the first character (or first > two, or ... and so on) and split your data accordingly. That way, > instead of searching through the WHOLE LIST for zulu, you'd only search > words starting with 'z' (or "zu", etc.). It would no doubt work better > combined with Kris's ideas. > > Later, > --jim >
Jim, this is a good solution, but I would argue that if he does indeed "read about data structures" (which I nebulously proposed he do), he might stumble upon a trie: http://en.wikipedia.org/wiki/Trie Which is basically what you propose. (I'm not trying to be condescending here, I'm really trying to point the OP to another data structure he could consider.) kris -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

