This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/6_Plat/6_Plat_Strings.md
2020-06-08 16:42:55 -04:00

3.2 KiB

slug title author order prerequisites
/plat/hashing Strings Benjamin Qi 6
Silver - Depth First Search
  • Tries
  • Hashing
  • Z
  • KMP
  • Manacher
  • Aho-Corasick
  • Suffix Array

Note: String algorithms do not appear very frequently. Hashing has appeared on gold (rarely).

General Resources

Tries

Hashing

Use to quickly test whether two substrings are equal.

My implementation can be found here. It uses two bases rather than just one to decrease the probability that two random strings hash to the same value. As mentioned in the articles above, there is no need to calculate modular inverses.

Problems

  • USACO
    • Gold Cownomics
      • Use two pointers; for a fixed l, keep extending r to the right until the positions l\ldots r explain spotiness.
      • Hashing gives you a way to quickly check whether two substrings of different cow types are equal. So for a single [l,r] pair you can check whether it works in O(N\log N) time (and you only need to check O(M) of these pairs in total).
      • Actually, it's possible to pass O(N^2M) (or even slower) solutions.
    • Gold Lightsout
      • figure out whether this actually needs hashing? (check ...)
  • Other (check ...)

Z, KMP

Manacher

Aho-Corasick

Suffix Array