shinghalrishabh's blog

By shinghalrishabh, history, 9 years ago, In English

How to find all occurences of each substring in the given string.Please give me some suggestions

  • Vote: I like it
  • -10
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

you can easily make that in O(N*N*N) time using Brute force. Then using hashes it can be reduced to O(N*N). You cAn make that in O(N*N) using KMP.

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Z-Function.

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

If I understood the problem correctly, then using suffix array + lcp should give performance between O(N) and depending on chosen algorithm for searching suffix array.

  • »
    »
    9 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    actually i asked to have the count for every substring in the string

    • »
      »
      »
      9 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Yes, there is no way of doing that in O(N) as there can be ~ N2 different substrings. I was thinking of problem where I had to count number of different substrings.