Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
Given:
For the purposes of this challenge, distance is the Levenshtein Distance. The median string is the string where the distance between itself and the furthest away string in the list is minimized. In other words, if you were to calculate the distance of the string furthest away for every string in the list, the median string would be the one with the shortest distance.
I recognize that my use of median is likely incorrect. In the event of a conflict, refer to the definition here as the intended one. There may be more than one string that fits the defintion of median string, in this case only 1 such string is required.
If you come up with a great solution that is not very memory efficient feel free to post it but if you can, limit memory consumption to 750MB. I have a feeling a trie may provide for a better solution, but the best I can come up with so far is below:
Update: ysth suggested a number of optimizations that I had already tried. He had the sense to try them together which makes it blazingly fast. While the algorithm is mine, credit for the optimizations go to him.
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Challenge: Find median string in a list
by blokhead (Monsignor) on Jul 04, 2007 at 19:18 UTC | |
by Limbic~Region (Chancellor) on Jul 05, 2007 at 01:05 UTC | |
|
Re: Challenge: Find median string in a list
by ysth (Canon) on Jul 04, 2007 at 22:16 UTC | |
by Limbic~Region (Chancellor) on Jul 05, 2007 at 01:26 UTC | |
|
Re: Challenge: Find median string in a list
by ysth (Canon) on Jul 04, 2007 at 18:34 UTC | |
by Limbic~Region (Chancellor) on Jul 04, 2007 at 19:06 UTC | |
by ysth (Canon) on Jul 04, 2007 at 19:56 UTC | |
by Limbic~Region (Chancellor) on Jul 05, 2007 at 01:09 UTC |