Ukkonen’s suffix tree

Build a tree from a word so you can look up different pieces of it later. To check whether банан contains нан, follow the branches that spell нан.

Append one character at a time. Split an edge when two suffixes diverge inside it. All leaves grow with the text. A separate terminal symbol ⊣ ends the string. Then follow edge labels from the root to read the query.