Ukkonen's Suffix Tree

Input7/15
b
a
n
a
n
a
$
Loading…
FastSlow
Step 1 / 0
Time Complexity
Best
O(n)
Average
O(n)
Worst
O(n)
Space Complexity
O(n)
StabilityFALSE
In-placeFALSE

Explanation

A suffix tree is a compressed trie containing all the suffixes of the given text. Using Ukkonen's O(n) algorithm, it can be built efficiently, enabling fast substring search and pattern matching.

Pseudo Code

1function Ukkonen(S):
2 activeNode = root
3 activeEdge = -1
4 activeLen = 0
5 remainder = 0
6
7 for i = 0 to |S|-1:
8 remainder++
9 while remainder > 0:
10 if no activeEdge:
11 activeEdge = i
12 if edge[activeNode][S[activeEdge]] missing:
13 add new leaf (Rule 2a)
14 else if S[activeLen on edge] == S[i]:
15 activeLen++ // Rule 3 (stop)
16 break
17 else:
18 split edge (Rule 2b)
19 follow suffixLink
Sponsor Ad