Welcome back.
In the previous video, we have discussed the recursive approach for solving the LCS question.
Let's now write the pseudo code for implementing this in code.
So we will have a function.
And this function will have some inputs.
And inside the function we will have to write the base case and the choice diagram.
Now we had previously discussed the base case.
So if I is greater than n minus one or j is greater than m minus one, where n and m are the lengths
of the two texts or strings given to us, and I is used to iterate over text one and j is used to iterate
over the characters of text two.
So if either of this has happened, then we would have hit the base case, and in that case we can just
return zero.
Now, when it comes to the choice diagram, remember there are two possibilities.
Now in the inputs over here we would be passing two indices I and J.
Now I would be the index that we would be considering in text one, and j would be the index that we
would be considering in text two.
Now, if these two characters, that is, if the character in text one at index I, and if the character
in text two at index j.
If these two are equal, then we would have to find one plus the LCS in the remaining two parts of the
two strings.
Now, if these two are not equal, then as we have seen, we have to call the same function recursively
twice.
So let's call it just f.
So in one case we would increment I.
So the input would be I plus one and j.
And the other case we would keep I as it is.
And we would have to increment j.
And then we would have to find the maximum between these two which would give the longest common subsequence
length.
So this is the pseudocode for the approach that we have discussed for solving the LCS question in a
recursive manner.