renovated2020's blog

By renovated2020, 9 years ago, In English

What is the most efficient algorithm or approach for finding most frequent k-length sub-string from a given string?

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

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

Hash all substrings of length K in O(N) and store this values in map O(NlogN)

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

    It would be O(NKlogN)

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

      Hash all substrings of length K

      If you implement rolling hashes it would be O(N*logN).

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

        hash(s1..k) = (hash(s0..k - 1) - s0 * pk) * p + sk

        by this relation hash values can calculate in O(1)