I am trying to write the recursive code for the Longest Common Subsequence problem and I run into the errror, "Maximum recursion limit reached." The code is:
function result=bin2(n,k) if (isempty(k) || isempty(n)) result = 0; elseif n == k result = bin2(n-1, k-1) +1; else result = max((bin2(n-1, k)), (bin2(n, k-1))); end
with the inputs n = [1,9,5,2,8,6,3,7,4,10] and k = [3,7,10,4,9,5,8,2,6,1] this code is adapted straight from the pseudocode in the text and should give the length of the LCS of the inputs. I don't understand what I've done wrong. Please advise.
Best Answer