From: Josh Cheek Date: 2009-10-21T05:49:48+09:00 Subject: Re: Randomly generated words from a set of letters --000e0cd2be98b12142047664002e Content-Type: text/plain; charset=ISO-8859-1 On Tue, Oct 20, 2009 at 10:26 AM, Ilan Berci wrote: > unknown wrote: > > > > > 1) Manually add the pre-defined word set to a DB table and randomly pull > > a word out as needed. > > > > 2) Each time I need a word, build a random word from the set of letters > > and compare to a dictionary somewhere to make sure I have a real English > > word. > > > > 3) Build a complete random word set one time (as in 1 but with all > > possible word combinations) and store in the DB to pull from randomly. > > > > > > So...what would you do? 1 is probably easiest....but 2 is more > > interesting for me from a problem solving standpoint. > > > > Just looking for some thoughts. > > > > Thanks, > > Matt > > Not sure what the difference is between 1 and 3 but option number 2 can > be grossly inefficient for little or no benefit. > > Option 3 is O(1) complexity and therefore I vote for it.. > > hth > ilan > > -- > Posted via http://www.ruby-forum.com/. > > What if you created some sort of a tree data structure, where each node represented a letter. (each node has at most 26 children) That seems like it should be more efficient, because for something like toon , tool , took , tooth , they all utilize the same series of paths to go through the too, and only diverge after that. So instead of 17 characters required for these 4 words, you only need 8. --000e0cd2be98b12142047664002e--