01A string as a number
You met hash functions in the hash table lesson: turn a key into a number, then use the number. For strings the standard choice is the polynomial hash. Read the string as digits of a number in base p:
h(s) = s[0]·p^(m−1) + s[1]·p^(m−2) + … + s[m−1] (mod M)
With A=1, B=2, p = 31 and M = 97, the string ABAB becomes 27. Equal strings always get equal hashes. Different strings usually get different hashes.
You compute it left to right with h = h·p + code(c), taking mod M at each step so the numbers stay small.