0

The problem is as following:

Given 2 strings X and Y, I want to find the all (longest) common substrings, hence all substrings that appear in X and in Y and are maximal. for instance - if X = gttcatwg, Y = twgacgtt. return gtt and twg, not substrings of those (for instance gt).

It is Given that both share the same letters (with the same number of appearances) and both of same length.

O(N) algorithm.

  • suggestion:
  1. build a generalized suffix tree. (Ukkonnen's algo)
  2. get all deepest (string wise) nodes that have leaves from both X and Y.
  3. from the above mentioned nodes remove all nodes that have suffix links in their subtree.
  • it seems like it is not enough. an example: X = abcabc Y= bcaabc should return : bc, abc and bca but returns abc and bca.
  • bc is a substring of either abc or bca. – n. m. could be an AI Dec 11 '22 at 18:43
  • but they're at different indices (the first two and the last two). – Abdullah Garra Dec 11 '22 at 19:17
  • Does your proposed algorithm use a terminal symbol? Please show the tree you create and what steps 2 and 3 do in detail. – n. m. could be an AI Dec 12 '22 at 04:55
  • As @n.m. said, you're suggestion is not detailed enough and it's hard to understand what you're trying to do... but for more information about the problem and implementation about it you should look for 'Longest common substring problem' https://en.wikipedia.org/wiki/Longest_common_substring_problem#:~:text=The%20longest%20common%20substrings%20of%20a%20set%20of%20strings%20can,in%20the%20subtree%20below%20it. – JackRaBeat Dec 12 '22 at 08:20

0 Answers0