views:

99

answers:

2

hi everybody

Is there any possible code for getting output in php(all possible word from word dictionary)

for example....for word "werflo"

  1. flower

  2. fowler

  3. reflow

  4. wolfer

+5  A: 
  1. Take your word list, order each word's letters (alphebetical or otherwise, as long as it's consistent).
  2. Associate each word with its ordered letter string
  3. Apply the same letter ordering to your input
  4. Find the matching words, which is now trivial as you just need to find those where the ordered letter sequence matches.
Joey
you were earlier :)
Vlad
Actually that algorithm was the very first one I heard of at University. Was the very first lecture I attended, so it kinda stuck ;-)
Joey
is there any php code is there johannes
adwiz
+3  A: 

I don't know PHP, but you could

  1. pre-sort all the words in the dictionary, remembering their original position (for example, "flower" will be stored as "eflorw"); sort the dictionary lexocographically;
  2. sort the letters in your input word the same way;
  3. with binary search find the sorted word within the sorted dictionary;
  4. by the stored index, find the original words in the original dictionary.
Vlad