3.8.8 · D1String Algorithms

Foundations — Suffix tree (conceptual)

2,157 words10 min readBack to topic

This page assumes you have seen nothing. We introduce each symbol, draw its picture, and say why the topic can't live without it. Read top to bottom — every item leans on the one before it.


1. What is a "string" ?

Example: banana.

Figure — Suffix tree (conceptual)

Why the topic needs it: the whole suffix tree is built out of pieces of this one row . If you can't picture as an addressed row of boxes, nothing later makes sense.


2. Index — the address of a character

We write to mean "the single character sitting at address ." In the figure above, a.


3. Substring — a contiguous chunk

Figure — Suffix tree (conceptual)

Why the topic needs it: the entire purpose of a suffix tree is to answer questions about substrings ("does nan occur?"). This is the object we hunt.


4. Prefix — a chunk that starts at the front

Why the topic needs it: the parent's key claim — "a substring is a prefix of some suffix" — uses this word. We define suffix next, then glue the two ideas together.


5. Suffix — a chunk that ends at the back (the star of the show)

For banana, the suffixes are the "tails":

start index suffix
0 banana
1 anana
2 nana
3 ana
4 na
5 a
Figure — Suffix tree (conceptual)

Why the topic needs it: the suffix tree is literally the tree of all these tails. There are exactly of them (one per start index), so a length- word has suffixes.


6. The bridge: substring = prefix of a suffix

Why the topic needs it: this is why a tree of suffixes can answer substring questions. If you store all tails and can walk their front-parts, you can find any chunk. Everything the parent note does rests on this line.


7. Alphabet and the terminal symbol $

Why the topic needs it: it guarantees "exactly leaves, one per suffix" — a fact the parent leans on for the size proof.


8. Tree words: root, node, edge, leaf, path

Figure — Suffix tree (conceptual)

Why the topic needs it: "a path is a substring" is the punchline of the whole structure. The tree is a machine where walking down = spelling a substring.


9. Edge labels as index pairs

Why the topic needs it: this trick is the entire reason a suffix tree fits in memory.


10. Big-O notation — the growth-rate ruler

Why the topic needs it: every payoff in the parent ("build ", "search ") is stated in this language. Here just means "the length of pattern " — the bars read as "length of."


Prerequisite map

String S as a row of boxes

Index i counting from 0

Length n

Substring S i to j

Prefix front part

Suffix tail part

Bridge substring is prefix of a suffix

Terminal symbol dollar

Tree words root node edge leaf path

Edge label as index pair i j

Big O growth ruler

Suffix tree

Read it as: rows of boxes give indices and length; indices carve out substrings; substrings specialise into prefixes and suffixes; the bridge fuses them; and the tree machinery plus the growth ruler turn it into the finished suffix tree.


Equipment checklist

Cover the right side and answer aloud before revealing.

In banana, what character is ?
a (0-based: b=0, a=1, n=2, a=3).
What is (the length) of banana?
; valid indices run to .
Is bnn a substring of banana?
No — it skips boxes, so it's a subsequence, not a contiguous substring.
Write the substring of banana.
nan.
How many suffixes does a length- word have?
Exactly (one per start index ).
Complete the bridge: a substring is a ____ of some ____.
a prefix of some suffix.
Why glue a $ to the end?
So no tail is the front of another tail; each suffix then ends at its own private leaf.
What does an edge label mean?
The substring — we point at the letters instead of copying them.
Why is the tree in space, not ?
Edges store two integers each, not copied text; edges 2 ints .
What does tell you about search cost?
It depends only on the pattern's length, not on the size of the text.
Out of one node, can two edges start with the same character?
No — distinct starting characters make the downward walk unambiguous.

Connections

  • Suffix tree (conceptual) (index 3.8.8) — the parent this page equips you for.
  • Trie — the uncompressed tree these symbols first build.
  • Suffix Array — the same suffix information stored as a sorted list.
  • Ukkonen's Algorithm — the linear-time way to actually construct the tree.
  • KMP Algorithm — another matcher that also cares about prefixes and suffixes.
  • Longest Common Substring — a payoff built on these foundations.
  • Burrows-Wheeler Transform — a cousin structure using the same suffixes.