-5

I need to design an algorithm in O (n) that given a string t of length n, calculate the number of different substrings of t.

corxil
  • 3
  • 1

1 Answers1

0
  1. Build a suffix automaton for the input string.

  2. Find the sum of maxLength[v] - maxLength[suffixLink[v]] for all states v, where maxLength[v] is the longest path from the root to the v state and suffixLink[v] is a suffix link for this state.

Constructing a suffix automaton in a linear time is a well-known problem. The second part is just a simple traversal. Thus, the total time complexity is O(n).

kraskevich
  • 18,368
  • 4
  • 33
  • 45
  • Thank you very much, it's exactly that I need. For if it helps someone else leave the link where I found the algorithm. [english google's translate](https://translate.google.es/translate?hl=es&sl=ru&tl=en&u=http%3A%2F%2Fe-maxx.ru%2Falgo%2Fsuffix_automata) [original in russian](http://e-maxx.ru/algo/suffix_automata) – corxil Jan 08 '15 at 20:16