Re: find words that contains some specific letters
- From: "John B. Matthews" <nospam@xxxxxxxxxxxxxx>
- Date: Mon, 01 Jun 2009 11:46:59 -0400
In article <78i4i2F1magkfU1@xxxxxxxxxxxxxxxxxx>,
"Giovanni Azua" <bravegag@xxxxxxxxxxx> wrote:
Hi Lew,
"Lew" <noone@xxxxxxxxxxxxx> wrote in message
I found it here "Stirling's approximation"
<http://en.wikipedia.org/wiki/Factorial#Rate_of_growth>
so it would be o(n! * log2 m) => O(n^n * log m) and this is NP ...
You only build the Set of permuted letters once. Then, following John
Once per search to be precise.
Matthews's suggestion to which you replied, you look up the n!One word lookup in the Set costs O(log m) binary search and not O(1).
permutations with an O(1) lookup in the Set of dictionary words.
So the actual complexity is just O(n!)
Therefore the O(log m) is *for each* generated permutation, and this is
why the multiplication i.e. O(n! * log m)
Thank you both for elucidating this. If I understand big O notation
correctly, the factorial term dominates the complexity, giving O(n!)
overall. Of course, I would welcome clarification.
Or one build the dictionary as a Map indexed by word letters in
alphabetical order with the values being corresponding Sets of
words using those letters. Then you only do an O(1) lookup into the
Map to find the single ordered permutation of the search term, then
return the matching Set directly. So now the overall lookup
complexity is that of sorting the letters in the search term.
Indeed, my approach is fine for small permutations (e.g. word puzzles,
password strength), but hashing on the sorted letters of the dictionary
entries beforehand gives what a appears to be an O(n log n) algorithm:
<http://en.wikipedia.org/wiki/Jumble>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
.
- Follow-Ups:
- Re: find words that contains some specific letters
- From: Giovanni Azua
- Re: find words that contains some specific letters
- References:
- find words that contains some specific letters
- From: Fralentino
- Re: find words that contains some specific letters
- From: Andrew Thompson
- Re: find words that contains some specific letters
- From: Fralentino
- Re: find words that contains some specific letters
- From: John B. Matthews
- Re: find words that contains some specific letters
- From: Giovanni Azua
- Re: find words that contains some specific letters
- From: Giovanni Azua
- Re: find words that contains some specific letters
- From: Lew
- Re: find words that contains some specific letters
- From: Giovanni Azua
- find words that contains some specific letters
- Prev by Date: Re: find words that contains some specific letters
- Next by Date: Re: find words that contains some specific letters
- Previous by thread: Re: find words that contains some specific letters
- Next by thread: Re: find words that contains some specific letters
- Index(es):
Relevant Pages
|