Efficient most common suffix algorithm?

Posted by taw on Stack Overflow See other posts from Stack Overflow or by taw
Published on 2010-06-07T06:50:10Z Indexed on 2010/06/07 6:52 UTC
Read the original article Hit count: 225

Filed under:

I have a few GBs worth of strings, and for every prefix I want to find 10 most common suffixes. Is there an efficient algorithm for that?

An obvious solution would be:

  • Store sorted list of <string, count> pairs.
  • Identify by binary search extent for prefix we're searching.
  • Find 10 highest counts in this extent.
  • Possibly precompute it for all short prefixes, so it doesn't ever need to look at large portion of data.

I'm not sure if that would actually be efficient at all. Is there a better way I overlooked?

Answers must be real time, but it can take as much preprocessing as necessary.

© Stack Overflow or respective owner

Related posts about string