3.2 KiB
3.2 KiB
id | title | author | prerequisites | ||
---|---|---|---|---|---|
strings | Strings | Benjamin Qi |
|
- 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
- CPC.11
- CP-Algorithms String Processing: Fundamentals
- CPH (26, String Algorithms)
Tries
Hashing
Use to quickly test whether two substrings are equal.
- Tutorial
- CPH 26.3
- cp-algorithms String Hashing
- Anti-Hash Tests
- On CodeForces educational rounds in particular, make sure to use random bases.
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 extendingr
to the right until the positionsl\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 inO(N\log N)
time (and you only need to checkO(M)
of these pairs in total). - Actually, it's possible to pass
O(N^2M)
(or even slower) solutions.
- Use two pointers; for a fixed
- Gold Lightsout
- figure out whether this actually needs hashing? (check ...)
- Gold Cownomics
- Other (check ...)
Z, KMP
- Tutorial
Manacher
- Has appeared at camp but not in platinum.
Aho-Corasick
- Has appeared in old gold.
- Tutorial