Question: ( 5 ) Assignment: Longest Common Substring Assignment Instructions: Step 1 : Implement an example of Longest common substring as described above. Your program should
Assignment: Longest Common Substring
Assignment Instructions:
Step : Implement an example of Longest common substring as described above.
Your program should take in strings, you can assume for this assignment that they are identical in length.
You should create a lookup table similar to the previous slide that shows the dynamically growing table that can ultimately be used to determine an answer.
For example, if your input strings were ABAB and BABA your programs output should be a D grid similar to what is shown in the previous slide along with the solution, which in this case is a tie between BAB and ABA since the largest value is a
Step : You can show just one of the winners in your solution since there is a tie in this example case.
Step : You can assume that there is at least a single shared character in both strings, so you do not need to solve for the case of no matching sequence.
Assignment Specifications:
You must use the C programming language to accomplish this.
#include
#include
#include
using namespace std;
Function to print the dynamic programming table
void printDPTableconst vector& dp const string& str const string& str
cout ;
for char ch : str
cout ch ;
cout endl;
for int i ; i strlength; i
if i
cout ;
else
cout stri ;
for int j ; j strlength; j
cout dpij;
cout endl;
Function to find the longest common substring
string longestCommonSubstringstring str string str
int n strlength;
int m strlength;
vector dpn vectorm ;
int maxLength ;
int endIndex ;
Fill the dynamic programming table
for int i ; i n; i
for int j ; j m; j
if stri strj
dpij dpi j ;
if dpij maxLength
maxLength dpij;
endIndex i;
else
dpij;
printDPTabledp str str; Print the DP table
return strsubstrendIndex maxLength, maxLength;
int main
string str str;
cout "Enter String : ;
cin str;
cout "Enter String : ;
cin str;
cout "Input Strings:" endl;
cout "String : str endl;
cout "String : str endl;
string result longestCommonSubstringstr str;
cout "Longest Common Substring: result endl;
cout "Length: result.length endl; Output the length of the longest common substring
return ;
do this code correct for the assignment
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
