Questions tagged [longest-substring]

Longest Substring is a classic computer science problem: given two strings, find the common strings, then return the string(s) in common with the greatest length.

The longest common substring problem is a derivative of the edit distance problem, which focuses on the most common typing errors:

  • namely character omissions
  • insertions
  • substitutions
  • reversals

The idea is to compute the minimum number of operations that it would take to transform one string into another. The longest common substring problem follows with the following constraints:

  • substitutions are forbidden
  • only exact character match, insert, and delete are allowable edit operations

References

181 questions
1
vote
1 answer

Longest common subsequence optimized

I'm currently trying to find and print longest common subsequence for 2 given strings. I use most common algorithm without recursion. It's simple task if I keep whole array, but I'm trying to optimize it a bit and use only 2 rows, what you can see…
Dcortez
  • 3,716
  • 1
  • 23
  • 29
1
vote
1 answer

Length of Longest Common sequence Python recursive function

I am trying to implement this function with recursion in python and I have a mistake. I can't understand what is the mistake, could you help me? The code: def LongestCommonSubsequence(X,Y,tailX,tailY): if tailX == tailY and tailX!='' and…
michael kova
  • 105
  • 2
  • 8
1
vote
1 answer

Least Common Subsequence with optimized space (two columns, since it's Markovian)

I'm trying to write LCS of two String objects using bottom-up dynamic programming. I'm able to get it to work properly with O(mn) space. However, as I could see, I don't need all the previous columns. So, I tried to modify it to get it fit in 2…
1
vote
2 answers

Java: Getting a substring from a string ending before a particular character

I have a String Millett Angle-Loc Weaver Extension 1 inch Rings, Black, Medium, Front/Rear Exte I would like to extract "Millett Angle-Loc Weaver Extension 1 inch Rings, Black, Medium, Front/Rear" from this String, ie, the substring before the…
yogesh9239
  • 2,910
  • 3
  • 15
  • 11
1
vote
1 answer

Implementing Longest Common Substring using Suffix Array

I am using this program for computing the suffix array and the Longest Common Prefix. I am required to calculate the longest common substring between two strings. For that, I concatenate strings, A#B and then use this algorithm. I have Suffix Array…
user3080029
  • 553
  • 1
  • 8
  • 19
1
vote
4 answers

Longest Common Substring

We have two strings a and b respectively. The length of a is greater than or equal to b. We have to find out the longest common substring. If there are multiple answers then we have to output the substring which comes earlier in b (earlier as in…
user3318603
  • 221
  • 3
  • 12
1
vote
2 answers

Generating a list of all the longest common substrings and a list of variations

High Level I am trying to collapse common substrings in a list of sentences and present only the areas that they differ. So taking this: Please don't kick any of the cats Please do kick any of the cats Please don't kick any of the dogs Please do…
theChrisMarsh
  • 308
  • 1
  • 7
1
vote
0 answers

Longest Substring Pair Sequence is it Longest Common Subsequence or what?

I have a pair of strings, for example: abcabcabc and abcxxxabc and a List of Common Substring Pairs (LCSP), in this case LCSP is 6 pairs, because three abc in the first string map to two abc in the second string. Now I need to find the longest valid…
exebook
  • 32,014
  • 33
  • 141
  • 226
1
vote
1 answer

Longest common substring of 2 strings implementation

I'm trying to implement the longest common substring algorithm in C, and after reading the post below, i'm really confused about the following part: Now, the greatest value is LCP[2]=3, but it is for SA[1] and SA[2], both of which start in the…
Fernando
  • 7,785
  • 6
  • 49
  • 81
1
vote
1 answer

Data-mining algorithm for dynamically consolidating recurring substrings?

I am trying to construct an artificial intelligence unit. I plan to do this by first collecting sensory input ('observations') into a short-term working-memory list, continually forming patterns found in this list ('ideas'), and committing those…
1
vote
2 answers

Finding the longest word in a string using dynamic programming?

I have started working on some algorithm problems when I saw a problem asking if I can find the longest word from a string (string does not have spaces just characters). After thinking for some time, I just wanted to confirm if I can use Dynamic…
Vik Singh
  • 1,563
  • 2
  • 19
  • 36
0
votes
3 answers

Why does this code work as expected if I use Visual C(Visual Sudio 2022) but doesn't if I use gcc 8.2?

I am new to C and still learning(currently doing some "LeetCode" challenges). I wrote a function that should return the longest common prefix in an array of strings. I tested with a couple different values and all works fine. But a string array…
OldCrow
  • 37
  • 6
0
votes
1 answer

determining a substring that is repeated in all of n strings and showing that substring in the output in java

i want to write a program that first takes the amount of n and then gets n strings (example: if n = 4 it gets 4 strings ) and then checks all the strings and finds the longest substring that contains in all the strings and prints that substring in…
Phantom
  • 75
  • 4
0
votes
0 answers

Known algorithms for incremental longest common substring?

Longest common substring is a well-known problem. I'm interested in identifying common substrings in a set of strings that is growing over time. Use case: suppose I'm emitting log messages inside a tight loop. Many logging libraries offer a flag for…
sp1ff
  • 95
  • 1
  • 5
0
votes
0 answers

Longest Common Substring from Trie

i'm trying to obtain the longest common substring from two strings and have coded a trie, but im not too sure how to obtain the longest common substring based on this trie. Could someone please help, thanks! class TrieNode: def __init__(self): …
marvel
  • 1