C/C++ Implementation for Longest Common Substring Algorithm

C++ The longest common substring problem is to find the longest string that is a substring of two or more given strings.

You can build a generalized suffix tree for a set of strings with multiple strings using this implementation. A suffix tree contains all the suffixes of the given text as their keys and positions in the text as their values.

string longestCommonSubstring(const string& str1, const string& str2)
{

  if(str1.empty() || str2.empty())
  {
    return 0;
  }
 
  int *curr = new int [str2.size()];
  int *prev = new int [str2.size()];
  int *swap = NULL;
  int maxSubstr = 0;
   string longest;
 
  for(unsigned int i = 0; i 

	

Leave a Reply

Your email address will not be published. Required fields are marked *