Skip to main content
gamedev.net
🔒 Locked

Search help

Started by __fold May 11, 2004 at 5:56 PM 6 replies 600+ views
Original Post
__fold
__fold
I''ve have a problem which is more or less the same as this. If one have a huge list of words and wants to find words that starts with the letter "A" and the letter at pos X is "B" and the length of the word is "Y". How would I represent my data in order to give as fast response as possible. Would brute force give good performance?
Forgemaster
Forgemaster
I do think that the quickiest way to do what you want IS brute force. Just loop through your words and at each loop test for the conditions. That would take time O(n).

I''m not sure if it could be done in time O(log n).
__fold
__fold
I think it can be done in O(log n) but i can''t waste memory cause it''s a huge set of data to search...
Sneftel
Sneftel
If that''s all you''ll ever need to search by, the ideal representation would be a hash table, with the hash function keyed on the first letter and the length. Then you''d just brute-force search the matching words. The runtime performance depends heavily on the nature of the datasets, but it should be close to O(1).


"Sneftel is correct, if rather vulgar." --Flarelocke
__fold
__fold
Sneftel: I''m not sure if a hash-table would help.
I want to be able to do this:

Search: a***e

And the result would be:
adore, aware, awake and so on.

I don''t understand how a hash-table would help me in this case. It would give me the starting letter and the length though...

(I''m really tired now, but tomorrow is another day.. )
Sneftel
Sneftel
So hold on. Your question seems to imply that you will always be searching by the first letter, some other letter in an arbitrary position, and the length. Is this not the case? I''m starting to think you''re writing a crossword/hangman solver.


"Sneftel is correct, if rather vulgar." --Flarelocke
__fold
__fold
Sneftel: The problem is the same. I just figured that if I would say that I was writing something that was really close to a crossword-solver, noone would help me.

If you are familiar with swedish cross-words you know that they are not to be beaten by I stupid program. In other countries besides sweden, the difficult cross-words are called swedish-crosswords... so?
Sneftel
Sneftel
For a situation like that, brute force is your only choice. Have the words in different containers, indexed by size, and search through the appropriate one.


"Sneftel is correct, if rather vulgar." --Flarelocke

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.