Given 3 strings X, Y and Z, the task is to find the longest common sub-sequence in all three given sequences
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
We need a 3D table to store the computed values.
Let's say for sub-sequences,
Now if X[i]==Y[j]==Z[k] then surely, we found a character which is common and we need to recur for the remaining ones
If they are not similar, we need to find maximum of three cases
So, if we formulate the above idea in to our recursion function then
Now, the above recursion will result to many overlapping sub problems. Hence, we need to convert the above to DP.
Obviously, visual illustration for the 3D DP calculation is not possible, but you can go through the computation for LCS between two strings to understand how this 3D table is being filled.
C++ Implementation:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer