in reply to Re: Longest Common SubSequence Not Working Correctly
in thread Longest Common SubSequence Not Working Correctly

I haven't look too close at your code, but it seems the "brute force" approach takes O(length($x) * length($y)) time.

The recursive method is a bit harder to estimate (at least for me), I'll try it anyway. With Memoize it will run in quadratic time as well in the worst case, since lcs will be called with all possible pairs of position shifts in the arguments. Memoize will only reduce this runtime if at least one of the strings is of the from $s x $n with $n >= 2.

But it uses many more method calls, which tend to be slow in Perl.

To test if this explanation really works you could benchmark both subs with increasingly long strings, and test if their runtime actually evolves similarly.