Answer to Question #326090 in Algorithms for Sahil Thakur

Question #326090

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). 


1
Expert's answer
2022-04-11T02:07:18-0400
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






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS