Longest common substring in linear timeComputing the longest common substring of two strings using suffix arraysFind longest common substring using a rolling hashWhich algorithm to use to find all common substring (LCS case) with really big stringsFinding the longest repeating subsequenceHow to find longest recurring pattern from lage string data set?Longest substring with consecutive repetitionsDoes the Longest Common Subsequence problem reduce to its binary version?Substring problems in suffix treesNumber of optimal solutions for Longest Common Subsequence (Substring) problemLongest common sequence matrix giving wrong answer

Are paving bricks differently sized for sand bedding vs mortar bedding?

Why did the Mercure fail?

Why can Carol Danvers change her suit colours in the first place?

2.8 Why are collections grayed out? How can I open them?

Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed

How to bake one texture for one mesh with multiple textures blender 2.8

Store Credit Card Information in Password Manager?

The screen of my macbook suddenly broken down how can I do to recover

250 Floor Tower

Aragorn's "guise" in the Orthanc Stone

A social experiment. What is the worst that can happen?

Why is it that I can sometimes guess the next note?

Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]

Which one is correct as adjective “protruding” or “protruded”?

"Spoil" vs "Ruin"

What does routing an IP address mean?

Is there any references on the tensor product of presentable (1-)categories?

Loading commands from file

Is there a name for this algorithm to calculate the concentration of a mixture of two solutions containing the same solute?

What if a revenant (monster) gains fire resistance?

Is it safe to use olive oil to clean the ear wax?

What does chmod -u do?

Travelling outside the UK without a passport

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)



Longest common substring in linear time


Computing the longest common substring of two strings using suffix arraysFind longest common substring using a rolling hashWhich algorithm to use to find all common substring (LCS case) with really big stringsFinding the longest repeating subsequenceHow to find longest recurring pattern from lage string data set?Longest substring with consecutive repetitionsDoes the Longest Common Subsequence problem reduce to its binary version?Substring problems in suffix treesNumber of optimal solutions for Longest Common Subsequence (Substring) problemLongest common sequence matrix giving wrong answer













2












$begingroup$


We know that the longest common substring of two strings can be found in O(N^2) time complexity.
Can a solution be found in only linear time?










share|cite|improve this question











$endgroup$
















    2












    $begingroup$


    We know that the longest common substring of two strings can be found in O(N^2) time complexity.
    Can a solution be found in only linear time?










    share|cite|improve this question











    $endgroup$














      2












      2








      2





      $begingroup$


      We know that the longest common substring of two strings can be found in O(N^2) time complexity.
      Can a solution be found in only linear time?










      share|cite|improve this question











      $endgroup$




      We know that the longest common substring of two strings can be found in O(N^2) time complexity.
      Can a solution be found in only linear time?







      algorithms time-complexity strings longest-common-substring






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited 2 hours ago









      Discrete lizard

      4,44011537




      4,44011537










      asked 2 hours ago









      Manoharsinh RanaManoharsinh Rana

      917




      917




















          3 Answers
          3






          active

          oldest

          votes


















          2












          $begingroup$

          Yes, the longest common substring of two strings can be found in $O(m+n)$ time, where $m$ and $n$ are the lengths of the two strings, assuming the size of the alphabet is constant.



          Here is an excerpt from https://en.wikipedia.org/wiki/Longest_common_substring_problem.




          The longest common substrings of a set of strings can be found by building a generalized suffix tree for the strings, and then finding the deepest internal nodes which have leaf nodes from all the strings in the subtree below it.




          Building a generalized suffix tree for two given strings takes $Theta(m+n)$ time using the famous ingenious Ukkonen's algorithm. Finding the deepest internal nodes that come from both strings takes $Theta(m+n)$ time. Hence we can find the longest common substring in $Theta(m+n)$ time.






          share|cite|improve this answer









          $endgroup$












          • $begingroup$
            I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
            $endgroup$
            – Apass.Jack
            52 mins ago



















          1












          $begingroup$

          It is unlikely that that a better algorithm than quadratic exists, let alone linear. For the related problem of finding subsequences, this is a known result: In the paper "Tight hardness results for LCS and other sequence similarity measures." by Abboud et al. , they show that the existence of an algorithm with a running time of $O(n^2-varepsilon)$, for some $varepsilon>0$ refutes the Strong Exponential Time Hypothesis (SETH).



          SETH is considered to be very likely true (although not universally accepted), so it is unlikely any $O(n^2-varepsilon)$ time algorithm exists.




          While finding a substring is a slightly different problem, it seems likely to be equally hard.






          share|cite|improve this answer











          $endgroup$












          • $begingroup$
            are you talking about subsequence? I am talking about substring.
            $endgroup$
            – Manoharsinh Rana
            2 hours ago











          • $begingroup$
            @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
            $endgroup$
            – Discrete lizard
            2 hours ago










          • $begingroup$
            Longest common substring is much easier than longest common subsequence. See my answer.
            $endgroup$
            – D.W.
            54 mins ago


















          1












          $begingroup$

          Yes. There's even a Wikipedia article about it! https://en.wikipedia.org/wiki/Longest_common_substring_problem



          In particular, as Wikipedia explains, there is a linear-time algorithm, using suffix trees (or suffix arrays).



          Searching on "longest common substring" turns up that Wikipedia article as the first hit (for me). In the future, please research the problem before asking here. (See, e.g., https://meta.stackoverflow.com/q/261592/781723.)






          share|cite|improve this answer









          $endgroup$












            Your Answer





            StackExchange.ifUsing("editor", function ()
            return StackExchange.using("mathjaxEditing", function ()
            StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
            StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
            );
            );
            , "mathjax-editing");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "419"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f105969%2flongest-common-substring-in-linear-time%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2












            $begingroup$

            Yes, the longest common substring of two strings can be found in $O(m+n)$ time, where $m$ and $n$ are the lengths of the two strings, assuming the size of the alphabet is constant.



            Here is an excerpt from https://en.wikipedia.org/wiki/Longest_common_substring_problem.




            The longest common substrings of a set of strings can be found by building a generalized suffix tree for the strings, and then finding the deepest internal nodes which have leaf nodes from all the strings in the subtree below it.




            Building a generalized suffix tree for two given strings takes $Theta(m+n)$ time using the famous ingenious Ukkonen's algorithm. Finding the deepest internal nodes that come from both strings takes $Theta(m+n)$ time. Hence we can find the longest common substring in $Theta(m+n)$ time.






            share|cite|improve this answer









            $endgroup$












            • $begingroup$
              I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
              $endgroup$
              – Apass.Jack
              52 mins ago
















            2












            $begingroup$

            Yes, the longest common substring of two strings can be found in $O(m+n)$ time, where $m$ and $n$ are the lengths of the two strings, assuming the size of the alphabet is constant.



            Here is an excerpt from https://en.wikipedia.org/wiki/Longest_common_substring_problem.




            The longest common substrings of a set of strings can be found by building a generalized suffix tree for the strings, and then finding the deepest internal nodes which have leaf nodes from all the strings in the subtree below it.




            Building a generalized suffix tree for two given strings takes $Theta(m+n)$ time using the famous ingenious Ukkonen's algorithm. Finding the deepest internal nodes that come from both strings takes $Theta(m+n)$ time. Hence we can find the longest common substring in $Theta(m+n)$ time.






            share|cite|improve this answer









            $endgroup$












            • $begingroup$
              I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
              $endgroup$
              – Apass.Jack
              52 mins ago














            2












            2








            2





            $begingroup$

            Yes, the longest common substring of two strings can be found in $O(m+n)$ time, where $m$ and $n$ are the lengths of the two strings, assuming the size of the alphabet is constant.



            Here is an excerpt from https://en.wikipedia.org/wiki/Longest_common_substring_problem.




            The longest common substrings of a set of strings can be found by building a generalized suffix tree for the strings, and then finding the deepest internal nodes which have leaf nodes from all the strings in the subtree below it.




            Building a generalized suffix tree for two given strings takes $Theta(m+n)$ time using the famous ingenious Ukkonen's algorithm. Finding the deepest internal nodes that come from both strings takes $Theta(m+n)$ time. Hence we can find the longest common substring in $Theta(m+n)$ time.






            share|cite|improve this answer









            $endgroup$



            Yes, the longest common substring of two strings can be found in $O(m+n)$ time, where $m$ and $n$ are the lengths of the two strings, assuming the size of the alphabet is constant.



            Here is an excerpt from https://en.wikipedia.org/wiki/Longest_common_substring_problem.




            The longest common substrings of a set of strings can be found by building a generalized suffix tree for the strings, and then finding the deepest internal nodes which have leaf nodes from all the strings in the subtree below it.




            Building a generalized suffix tree for two given strings takes $Theta(m+n)$ time using the famous ingenious Ukkonen's algorithm. Finding the deepest internal nodes that come from both strings takes $Theta(m+n)$ time. Hence we can find the longest common substring in $Theta(m+n)$ time.







            share|cite|improve this answer












            share|cite|improve this answer



            share|cite|improve this answer










            answered 56 mins ago









            Apass.JackApass.Jack

            13.3k1939




            13.3k1939











            • $begingroup$
              I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
              $endgroup$
              – Apass.Jack
              52 mins ago

















            • $begingroup$
              I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
              $endgroup$
              – Apass.Jack
              52 mins ago
















            $begingroup$
            I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
            $endgroup$
            – Apass.Jack
            52 mins ago





            $begingroup$
            I did not see @D.W's answer, possibly because I was interrupted while writing my answer.
            $endgroup$
            – Apass.Jack
            52 mins ago












            1












            $begingroup$

            It is unlikely that that a better algorithm than quadratic exists, let alone linear. For the related problem of finding subsequences, this is a known result: In the paper "Tight hardness results for LCS and other sequence similarity measures." by Abboud et al. , they show that the existence of an algorithm with a running time of $O(n^2-varepsilon)$, for some $varepsilon>0$ refutes the Strong Exponential Time Hypothesis (SETH).



            SETH is considered to be very likely true (although not universally accepted), so it is unlikely any $O(n^2-varepsilon)$ time algorithm exists.




            While finding a substring is a slightly different problem, it seems likely to be equally hard.






            share|cite|improve this answer











            $endgroup$












            • $begingroup$
              are you talking about subsequence? I am talking about substring.
              $endgroup$
              – Manoharsinh Rana
              2 hours ago











            • $begingroup$
              @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
              $endgroup$
              – Discrete lizard
              2 hours ago










            • $begingroup$
              Longest common substring is much easier than longest common subsequence. See my answer.
              $endgroup$
              – D.W.
              54 mins ago















            1












            $begingroup$

            It is unlikely that that a better algorithm than quadratic exists, let alone linear. For the related problem of finding subsequences, this is a known result: In the paper "Tight hardness results for LCS and other sequence similarity measures." by Abboud et al. , they show that the existence of an algorithm with a running time of $O(n^2-varepsilon)$, for some $varepsilon>0$ refutes the Strong Exponential Time Hypothesis (SETH).



            SETH is considered to be very likely true (although not universally accepted), so it is unlikely any $O(n^2-varepsilon)$ time algorithm exists.




            While finding a substring is a slightly different problem, it seems likely to be equally hard.






            share|cite|improve this answer











            $endgroup$












            • $begingroup$
              are you talking about subsequence? I am talking about substring.
              $endgroup$
              – Manoharsinh Rana
              2 hours ago











            • $begingroup$
              @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
              $endgroup$
              – Discrete lizard
              2 hours ago










            • $begingroup$
              Longest common substring is much easier than longest common subsequence. See my answer.
              $endgroup$
              – D.W.
              54 mins ago













            1












            1








            1





            $begingroup$

            It is unlikely that that a better algorithm than quadratic exists, let alone linear. For the related problem of finding subsequences, this is a known result: In the paper "Tight hardness results for LCS and other sequence similarity measures." by Abboud et al. , they show that the existence of an algorithm with a running time of $O(n^2-varepsilon)$, for some $varepsilon>0$ refutes the Strong Exponential Time Hypothesis (SETH).



            SETH is considered to be very likely true (although not universally accepted), so it is unlikely any $O(n^2-varepsilon)$ time algorithm exists.




            While finding a substring is a slightly different problem, it seems likely to be equally hard.






            share|cite|improve this answer











            $endgroup$



            It is unlikely that that a better algorithm than quadratic exists, let alone linear. For the related problem of finding subsequences, this is a known result: In the paper "Tight hardness results for LCS and other sequence similarity measures." by Abboud et al. , they show that the existence of an algorithm with a running time of $O(n^2-varepsilon)$, for some $varepsilon>0$ refutes the Strong Exponential Time Hypothesis (SETH).



            SETH is considered to be very likely true (although not universally accepted), so it is unlikely any $O(n^2-varepsilon)$ time algorithm exists.




            While finding a substring is a slightly different problem, it seems likely to be equally hard.







            share|cite|improve this answer














            share|cite|improve this answer



            share|cite|improve this answer








            edited 2 hours ago

























            answered 2 hours ago









            Discrete lizardDiscrete lizard

            4,44011537




            4,44011537











            • $begingroup$
              are you talking about subsequence? I am talking about substring.
              $endgroup$
              – Manoharsinh Rana
              2 hours ago











            • $begingroup$
              @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
              $endgroup$
              – Discrete lizard
              2 hours ago










            • $begingroup$
              Longest common substring is much easier than longest common subsequence. See my answer.
              $endgroup$
              – D.W.
              54 mins ago
















            • $begingroup$
              are you talking about subsequence? I am talking about substring.
              $endgroup$
              – Manoharsinh Rana
              2 hours ago











            • $begingroup$
              @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
              $endgroup$
              – Discrete lizard
              2 hours ago










            • $begingroup$
              Longest common substring is much easier than longest common subsequence. See my answer.
              $endgroup$
              – D.W.
              54 mins ago















            $begingroup$
            are you talking about subsequence? I am talking about substring.
            $endgroup$
            – Manoharsinh Rana
            2 hours ago





            $begingroup$
            are you talking about subsequence? I am talking about substring.
            $endgroup$
            – Manoharsinh Rana
            2 hours ago













            $begingroup$
            @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
            $endgroup$
            – Discrete lizard
            2 hours ago




            $begingroup$
            @ManoharsinhRana Ah, I see. The problems are similar, and it is hard to find results for the string variant. I think there are similar results for the substring problem, but they are not easy to find. You could try looking at papers that cite "Quadratic conditional lower bounds for string problems and dynamic time warping" by Bringmann and Künnemann, as their program lead to a lot of results related to this problem.
            $endgroup$
            – Discrete lizard
            2 hours ago












            $begingroup$
            Longest common substring is much easier than longest common subsequence. See my answer.
            $endgroup$
            – D.W.
            54 mins ago




            $begingroup$
            Longest common substring is much easier than longest common subsequence. See my answer.
            $endgroup$
            – D.W.
            54 mins ago











            1












            $begingroup$

            Yes. There's even a Wikipedia article about it! https://en.wikipedia.org/wiki/Longest_common_substring_problem



            In particular, as Wikipedia explains, there is a linear-time algorithm, using suffix trees (or suffix arrays).



            Searching on "longest common substring" turns up that Wikipedia article as the first hit (for me). In the future, please research the problem before asking here. (See, e.g., https://meta.stackoverflow.com/q/261592/781723.)






            share|cite|improve this answer









            $endgroup$

















              1












              $begingroup$

              Yes. There's even a Wikipedia article about it! https://en.wikipedia.org/wiki/Longest_common_substring_problem



              In particular, as Wikipedia explains, there is a linear-time algorithm, using suffix trees (or suffix arrays).



              Searching on "longest common substring" turns up that Wikipedia article as the first hit (for me). In the future, please research the problem before asking here. (See, e.g., https://meta.stackoverflow.com/q/261592/781723.)






              share|cite|improve this answer









              $endgroup$















                1












                1








                1





                $begingroup$

                Yes. There's even a Wikipedia article about it! https://en.wikipedia.org/wiki/Longest_common_substring_problem



                In particular, as Wikipedia explains, there is a linear-time algorithm, using suffix trees (or suffix arrays).



                Searching on "longest common substring" turns up that Wikipedia article as the first hit (for me). In the future, please research the problem before asking here. (See, e.g., https://meta.stackoverflow.com/q/261592/781723.)






                share|cite|improve this answer









                $endgroup$



                Yes. There's even a Wikipedia article about it! https://en.wikipedia.org/wiki/Longest_common_substring_problem



                In particular, as Wikipedia explains, there is a linear-time algorithm, using suffix trees (or suffix arrays).



                Searching on "longest common substring" turns up that Wikipedia article as the first hit (for me). In the future, please research the problem before asking here. (See, e.g., https://meta.stackoverflow.com/q/261592/781723.)







                share|cite|improve this answer












                share|cite|improve this answer



                share|cite|improve this answer










                answered 1 hour ago









                D.W.D.W.

                102k12127291




                102k12127291



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Computer Science Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    Use MathJax to format equations. MathJax reference.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f105969%2flongest-common-substring-in-linear-time%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

                    Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

                    Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe