Coders Packet

Longest common subsequence in CPP

By Anamika

The project named longest common subsequence is in CPP language. It takes two user input strings and provides us with the longest common subsequence on the basis of the input given by the user.

The code is in CPP in which we are supposed to enter two strings and we will get the output based upon our input in the form of the longest common subsequence of the two strings. The code uses dynamic programming for the output generation, except for recursion. It uses a 2D table of dimensions a+1 and b+1, where a = length of one string, b= length of another string. Traverse the 2D array starting from t[a][b]. Follow this procedure  for every cell t[i][j]                                                                                                                                                                                            

a) If characters corresponding to t[i][j] are same ( A[i-1] == B[j-1]), then include this character as part of LCS.                         

b) Otherwise compare values of t[i-1][j] and t[i][j-1] and go in direction of greater value.


I am hereby attaching the screenshot of the output of my code.


Download Complete Code


No comments yet