Suffix tree: Difference between revisions
update task description.
m (→{{header|Perl}}: updating output as well) |
(update task description.) |
||
Line 1:
{{draft task}}
A [[wp:suffix tree|suffix tree]] is a data structure commonly used in [[wp:string algorithms|string algorithms]]
Given a string S of length n, its suffix tree is a tree T such that:
* T has exactly n leaves numbered from 1 to n.
* Except for the root, every internal node has at least two children.
* Each edge of T is labelled with a non-empty substring of S.
* No two edges starting out of a node can have string labels beginning with the same character.
* The string obtained by concatenating all the string labels found on the path from the root to leaf i spells out suffix S[i..n], for i from 1 to n.
Such a tree does not exist for any string. To ensure existence, a character that is not found in S must be appended at its end. The character '$' is traditionally used for this purpose.
There are several ways to implement the tree data structure, for instance how edges labels should be encoded. Latitude is given in this matter.
The computation time for an efficient algorithm should be <math>O(n)</math>, but such an algorithm might be difficult to implement. An easier, <math>O(n^2)</math> algorithm is accepted.
=={{header|Perl}}==
|