The Gateway to Computer Science Excellence
0 votes
57 views

 

in Algorithms by (195 points) | 57 views
+1
D) O(mn)

1 Answer

0 votes

For the general case of an arbitrary number of 

input sequences, the problem is NP-hard. When the number of sequences is constant, the problem is solvable in polynomial time by dynamic programming (see Solution below). Assume you have NNsequences of lengths { n_{1},...,n_{N}}n_{1},...,n_{N}. A 

naive search would test each of the { 2^{n_{1}}}2^{n_{1}}subsequences of the first sequence to determine whether they are also subsequences of the remaining sequences; each subsequence may be tested in time linear in the lengths of the remaining sequences, so the time for this algorithm would be

{O(2^(n_(1))sum(n(i)):i>1}

O\left(2^{n_{1}}\sum _{i>1}n_{i}\right).

For the case of two sequences of n and elements, the running time of the dynamic programming approach is O(n × m)

source : https://en.m.wikipedia.org/wiki/Longest_common_subsequence_problem

by Junior (977 points)

Related questions

0 votes
3 answers
1
0 votes
0 answers
2
asked Jan 23, 2019 in Algorithms by Shankar Kakde (195 points) | 72 views
+1 vote
1 answer
3
asked Oct 2, 2018 in Algorithms by Shankar Kakde (195 points) | 68 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,309 answers
198,336 comments
105,023 users