Find a longest common subsequence between following strings:
String1= {1, 2, 3, 4, 5, 6, 7, 8}
String2=<1,2,0,1,1,5,6,5>
(Neatly show all the steps and also write the algorithm)(Analyze the running time of the given problem).
function longest_subsequance(string1, string2) {
let max = 0, num = 0;
for (let i = 0; i <= string1.length; i++) {
if (string1[i] == string2[i]) { num++ } else {
max = Math.max(num, max) num = 0 }
}
return Math.max(num, max)
}
longest_subsequance('{1, 2, 3, 4, 5, 6, 7, 8}', '<1,2,0,1,1,5,6,5>')
// 2
Comments
Leave a comment