Skip to content

Rabin-Karp for String Matching: Mention rolling hash #1323

@jxu

Description

@jxu

Article: Rabin-Karp for String Matching

I guess the code implements the rolling hash version of the algorithm, which is vital to the good performance versus just hashing every possible substring. https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm

With a good hash function, the hash collision rate is low, so it would only take on average O(t) time to compute the rolling hashes, then O(s) time to check each match to see if it's valid. For a single match, this is O(t + s) = O(t). For m matches, I guess this is O(t + ms).

The worst case is if the hash function matches every time. Then the performance degrades to O(ts).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy