More string tools: Z, Manacher and suffix arrays

One short string hunted inside a long one, the picture that every tool in this lesson redraws with a different trick.
Someone gives you a text of 100,000 letters and asks: what is the longest palindrome inside it? A palindrome is a string that reads the same forwards and backwards, like racecar. The simple method takes each possible middle and grows outward while the two sides match. On the worst text that costs 100,000 × 100,001 ÷ 2 = 5,000,050,000 steps. A second person asks: this text will be searched ten thousand times, each time for a new word. A fresh scan every time is also slow.
By the end you will be able to compute a Z-array, find the longest palindrome in about 2 steps per letter with Manacher’s algorithm, build and search a suffix array, and parse 3+2*2 with one stack (LeetCode 227 and 224).
The history (optional)
Glenn Manacher published his palindrome algorithm in the Journal of the ACM, volume 22, issue 3, July 1975, pages 346 to 351. Robert Boyer and J Strother Moore published their skipping search in Communications of the ACM, October 1977. Udi Manber and Gene Myers presented suffix arrays at the SODA conference in 1990. Their abstract says suffix arrays take three to five times less space than the older suffix tree, and three to ten times longer to build.
Before you start. String Algorithms (finding the needle) gave you the idea that powers this lesson: never throw away what a partial match taught you, so your position in the text only moves forward. Linked Lists, Stacks & Queues gave you the stack, a list where you only add and remove at one end. Clinic #11: Binary Search gave you binary search, which finds a value in a sorted list by halving the range, and Arrays & Strings gave you indexes. In this lesson a prefix is the first few letters of a string, and a suffix is the last few letters.