What are the maximum and minimum number of edges in a suffix tree? I know the maximum is 2m-1, but I don't understand why that is so.
1 Answers
First, about the maximum number of edges:
It's quite easy to understand if you think of the edges as coming in two flavours: Edges that lead to a leaf node, and edges that lead to an inner node. In the following, I'll assume that the string the suffix tree is constructed for is N
characters in length.
About the edges leading to leaves. There must be exactly one leaf for every suffix, and every leaf has only one inbound edge (and no outbound edges). So there must be
N
edges leading to leaves.About the edges leading to inner nodes. Like with leaf nodes, inner nodes, too, have only one inbound edge each. Therefore, to determine how many edges leading to inner nodes there can possibly be, it suffices to determine how many inner nodes there can be. So, what is the maximum possible number of inner nodes?
For this it is important to see that inner nodes are only inserted into the suffix tree at branching points, i.e. the number of outbound edges of an inner node is always at least 2 (if there was only one outbound edge, the inner node wouldn't have been constructed in the first place). But every outbound edge must eventually lead to a leaf node (possibly after going through further inner nodes). In other words, every inner node inserted into the tree increases the total number of leaf nodes by at least 1. Furthermore, even a tree with no inner nodes whatsoever must have at least one edge going out of the root node (unless the tree is empty). Hence, in a non-empty tree, the total number of leaves
L
must beL >= I + 1
where
I
is the number of inner nodes. Conversely, the number of inner nodes isI <= L - 1 = N - 1
Returning to the original question, the number of edges leading to inner nodes is, as we said, the same as the number of inner nodes, hence it is also bound by
N - 1
.
We conclude that the total number of edges is the number of edges leading to leaves (N
) plus the number of edges leading to inner nodes (<=N-1
), hence its maximum is bound by
N + (N-1) = 2N - 1
quod erat demonstrandum.
Regarding the minimum number of edges: This follows the same principle, i.e. we calculate the number of edges leading to leaves and the number of edges leading to internal nodes, and then add them together.
The number of nodes leading to leaves is always N
, i.e. N
is the maximum as well as the minimum possible.
The number of nodes leading to internal nodes, however, may be zero. E.g. when the input string has no repeated elements, such as abcdef
, there are exactly N
edges, each from the root straight to a leaf. No branching points, no internal nodes. Hence the minimum number of edges leading to internal nodes is 0.
In conclusion, the minimum number of edges is N + 0 = N
.

- 68,383
- 11
- 101
- 131
-
A tree on `n` nodes has `n-1` edges. Since the maximum number of nodes in a suffix tree is `2n-1`, we conclude that the maximum number of edges is `2n-2`. – mrk Oct 04 '14 at 14:35
-
@saadtaame Your statement "a tree on n nodes has n-1 edges" is only true if you count the root node. If you do that, a suffix tree has up to 2n nodes, not 2n-1. So the result is the same as above. (The example of a suffix tree that has exactly 2n-1 edges is a suffix tree for a string of length n=1. It consists of a root node and 1 edge leading to the only leaf. That's 1=2n-1 edges.) – jogojapan Oct 05 '14 at 02:17
-
I forgot to mention that the tree should be binary to establish that result. – mrk Oct 05 '14 at 08:28
-
@saadtaame What exactly are you getting at? What are you trying to tell me? – jogojapan Oct 05 '14 at 10:11
-
That's a general result for trees.. just wanted to add that. You could have used this result directly. – mrk Oct 05 '14 at 10:21
-
@saadtaame What's that remark about binary trees? Suffix trees are not binary. – jogojapan Oct 05 '14 at 15:32
-
@jogojapan In your reply at http://stackoverflow.com/a/13392490/1330329 , you argued for a maximum of N-2 inner nodes. As there is exactly one edge leading to every leaf, inner node, NOT to the root, there could be at most 2N-2 edges. Here, you give the example of the string of length N=1, so that would actually be an empty string with just $ padded? What is actually the minimum (non-empty) suffix tree? Already for "a$", you would see 2 leafs, 1 root, 0 internal nodes, 2 edges? – bug313 Sep 08 '15 at 05:32
-
Follow-up: I think part of the confusion comes form the fact that "$" is treated differently across literature. Some text books refer to 'banana' as a text of length N=6 but leaf number of N+1, because they explicitly add $ (with own root-leaf-edge), but don't see it as part of the text. On the other hand, https://en.wikipedia.org/wiki/Suffix_tree uses an illustration where $ is added, but not really accounted for, listing last suffix 'a$'. Other (most?) places, it would be N=7, explicitly containing $ as part of the string and with its own leaf node. – bug313 Sep 08 '15 at 05:41
-
@bug313 Sorry I don't fully understand what the confusion is about. But let me answer the question about strings of length 1: Yes, if you follow the convention that the last character of the string must be '$', then a string of length 1 would be a string consisting only of the '$' sign. Keep in mind that the idea of the '$' character is simply that the last character must be a character that doesn't occur anywhere else in the string. So for a string of length 1, it doesn't really matter what that one character is. (This also implies that I include the '$' in the counting for n.) – jogojapan Sep 09 '15 at 05:40
-
Yes, I understood what the sentinel is used for and that is merely conventions of how to count it. All of this aside, what I actually meant is that for all strings of length N with N>1, the suffix tree has at most 2N-2 edges. Or put differently: If there are at least two leaf nodes, then the upper bound for number of edges is 2N-2 instead of 2N-1, because there can be at most N-2 inner nodes (branching, non-root, non-leaf) as you demonstrated in the other thread linked above. – bug313 Sep 09 '15 at 14:32