Title: Suffix Tree
1Suffix Tree
2Suffix Tree Definition
- Suffix tree T ?? ?????? S ?????? n , ??? ??
????? ?? ????? n ???? ???????? ?-1 ?? n. - ??? ???? ?????? (??? ??????) ?? ????? ??? ?????
- ?? ??? ?????? ?? ?????? ?? ???? ?? S.
- ??? ??? ????? ??????? ????? ???? ??? ??????? ???
??????? ?????? ????? ???. - ????? ?????? ??? ??? i, ????? ?? ????????
???????? ?? ??? ?????? ?????? ?-i, ????? ????
?? S ??????? ????? ?-i.
3?????
4??????? ????????
- ????? ????? P ????? m ??????? T ????? n
- ????? ?? ?????? ?????? ???????? ?????? ???????
- ????? ??????? ???????? ? DNA
5????? ?????? ????? P ????? T
??? ?? ?? ???????, ?? ????, ?? aw ???? a w
y a w x a w x z
6????? - ????
z
7
10
a
w
x
z
x
z
y
y
w
9
a
a
a
w
w
x
y
w
x
x
a
x
z
a
z
z
a
w
4
w
w
x
x
6
8
z
z
1
3
z
5
2
7????? - ????
8????? - ???
???? ???? 7,4,1 ??? ?? ????? ???????? ?? P ? - T
9?????????? ??????? ?????
- ?? P ????? ?? ?????? ?? T, ?? ??? ????? ?????
????? ?? ???? ????? ?? T - ?????? singing ??? ?????? ?? ????? singing in
the rain ?? ??????? Im singing in the rain - ??? ?? P ??? ?? ?????? ?? T ??? ????? ????? ?????
??? ?????? ????? ?????? ???? ?????, ??? ?????? ??
suffix Tree - ???????? ?? P ? T ???? ????? ????? ?????
??????? ?????? ?????? ? - P ?????? ???.
10?????? ??? ????? ?????? ????? P ???? T
- ??? ????? ???, ????
- ???? ?????? ? p ???? ????? ?? ????? ?????
?????? ??? , ???? - ??? ???? DFS ??? ??? ??? ????? ?? ????? ?????
(???? ????? ???? ???? ?? ?????), ??? ???? ?? ????
? O(n).
??? ????? ???? ??????? ?? ???? ????? ?? ???
11???????? ????? ?????? ?? ??????
- ????? ????
- ???? ??? ??? ???? ???? ????? (?????
??????? ????) - ????? ???????? ????? ????? ???,
. - ??????
- ???? ? - ?? ?? ??????? ????? ?? ?? ???????
?? S ? 1 ?? i. - ???? ??? ????? ?????? ?? ???? ???? 1 ?? ???,
??? ????? ?? ??????? S. - ??? ???? ???? ??? ?"? ????? ??????
????? ????? ?????? ??????, ??? ?????? ????? ?????
???? ?? (????? ????? ??
???? ?? ??????? ?? ??).
12???????? ????? - ????
- ?? ???? ?????? ??? ???? ??? (u,v) ??? ???? ??
???? ?????? ?? ????? ???? ???? ??? ???? ???
?????? ???? ????????, ????? ? w. ??? ??????
??????? ????? ?? ????? ???? - ?????? ?????. - ?? ???? ?????? ??? ????? w , ????? ?? ??? ????
????? ??, ????? ????? ?????? ???? ????? ?? ????
?????, ??? ????? ??????. -
13????? ????????? ??????
????? ????????? ?????? ??????? Sawyawxawxz
14????? - ????
4
Sawyawxawxz
15????? - ????
w
aw
xawxz
yawxawxz
x
7
z
6
xawxz
yawxawxz
yawxawxz
awxz
???'...
16???? ???????? ???? ??????
- ??????? ????????? ?? E. Ukkonen
- ?? ????? ???????
- ???????? On-Line
- ????? ??? ????? ?? ?? ??? ??? ??????, ????
??? ?? ????? Suffix Tree ?????? ??????? ???????
?? ??.
17????????? ?? Ukkonen
- ???? ? - ?? ??? ?????? ????????
. ?? ???? ???? ?????? ????? ?? ?? ??????,
???? ?? ??? ?? ?????. - ????? ???? ?? ?????????
- ????????? ????? ? n ?????, ?? ?????? ? i1 ,
??? ???? ???? ??? - ????? ? i1 ????? ? i1 ??????, ????? ??? ???
???? ??
18High-level Ukkonen algorithm
- Construct tree
- For i from 1 to n-1 do
- begin phase i1
- for j from 1 to i1
- begin extention j
- Find the end of the path from the root
labeled - in the current tree. If needed, extand
that - path by adding character
, - thus assuring that string
is in the tree. - end
- end
19??????
????
????? ???? ??
, ??? ?????? ? j ,
???? ???? ?? ???? ?? ??? ??????, ????? ??
?? ?????? ???? ????
???.
20???? ???????
??? ????? ??? ?????? ?????? ?????? ????.
?????? ??? ?????? ?? ?? ?????? ?? ???
???? ?????? ?? ???? ??????? ???? ???? ??
??? ??? ??? ????? ?????? ????? ?? ?? ???
, ??? ???? ????? ????? ??? ?????? ?????
?? (?? ?? ???). ????? ?? ???? ????? ???
???? ??????? ???? , ??????? ??? ??? ???
. ?? ?????? ???? ???, ?? ???? ?? ?????
???? ???? . ???? ???? ????? ?-j.
??? ????? ???? ????? ??? ?????? ????? ??
?????? ??? ? . ?????
?? ?? ???? ???.
21????? ????? ???????
??? Saxabxb, ????? ???? ????
5
x
bx
a
4
xabx
xabx
bx
2
?????? ??????? ??????? ????
1
3
22????
?? ???? ?? ????? ????? ????? ?????? , ?
???, ?? ?? ????? j ?? ???? ????
???, ????? ??? ???? ???,
??? ???? ???
?????
???? ???? ???? ?? ??? ?????? ?? ????? ???
????? ????? ?????, ?? ????? ?????? ??????, ???
??? ???? ???? ?????, ?? ??? - ?? ????? ?? ??????
.
23Suffix link
??? ?????? ?????, ?? ? ??? ?? ????, ?
??? ?? ?????? (???? ????). ??? ???? ??????
??????? ????? ??? ?????? ??? , ?? ?????
???? ????? ?? ????? ????? ,
??? ????? ?- ?- ?????
suffix link
???? ?????
?? ??? ? - suffix link ? -
????? ????? ?? ???.
24???
?? ???? ?????? ???? ?? ????? ?????
????? ??? ?????? ? j ?? ???? ?????,
??? ???? ??? ??????? 1. ????? ?????? ???
??????? ???? ???? ?????? ?? ???, ?? 2. ??????
???? ?????? ???? ?????? ?????? ? j1- ??
???? ?????.
????? ????????? ?????? ????? Suffix link ???
?????? ???? ?? ??????
25????? ? suffix link ????? ???
????? ??????? ??????? ca ????? ????? ???????,
?????? ???? 3. ?????? ???? 4 ?? ???? ????, ?????
?? ????? ??????? a.
????? ?????? ? 31 ?? ????? ???????, ????? ?????
?????? ?? ?????? ca ???? suffix - link ?????
??????? a
26????? ??????
- ????????? ?? Ukkonen, ??? ???? ?????? ????
?????? ???? suffix link ???? ???? ?????? ????
????.
- ???? ?? ?? , ?? ????? ?????? v ?? ?????
????? ??? ????? ???? ?- ??
????? ?????
27????? ? Suffix link ????? ????
???? ????? ?? ??? ??????? ???????? ????? ? -
1. ??? ??????? ????? ????
???? ???? ?? , ?????? ????? ??????? ??????
????? ??????? ??? . ??? ????? ????? ???? ???? ??,
????? ???? ?? ?? ??? 1 ?? ??????. 2. ???
????? ?? ???? ??????? ???? ??? (????? ?
) ????? ?? . ???
?????? ???? 2 ???? ????? ?? ???? ?? . ???
????? ???, ??? ???? ?? 1 ????? v, ????? ??? ?
suffix link ?????? ???? ? , ?????? ???
???? ??? ?????? . ??? ?????? ??? ???
???? ?? ???? ????? ?? ???? ???? ??
??????, ??? ??????.
28??????? ?????
??? ?????? ?? ??????? ? -
???? ????? ???? ????? ???? ???????
?? ??? ??????, ??? ??? ????? ???? ???
????? ??? - ???? ?????, ?? ??? ???? suffix link.
?? ???? ? ?? ?????? ?? ???? ???? ?????, ???
v ????? ?????, ????? ??? ? suffix link ?????
???? ? , ?????? ????? ??? ?????? ?????? ?
?? ????, ??? ???? ?? ?????? - ??? ???? ??????.
???? ?? ???? ?? ??? ????? ??? ????
suffix link, ????? ?? ??? ??? ???? ??? ?????
(???? ??? ???? ???? ????? ???? 3 ????), ??? ????
??? ????? ??? ????? ?????, ??? ?? ???? ?????
?????, ?? ?? ???? suffix link. ??? ???? ??????
????? ??? ??? ????? ??? ???.
29Single extension algorithm
30????? ????? j ???? jgt1
S(v)
v
a
bc
abcd
J-1
d
31Skip/count
???? ? g ?? ????? ?? , ???? ? d ?? ????
?????? ?? ???? ?????? ? ?????? . ??
dltg ??? ???? ??? ????? ???? . ???? gg-d, ? hd1
, ?? ???? ????? ????? ?? ???? ?????? ?????? ?????
. ????? ?? ?? ??? ???? , ??? ?????
??? ????? ?? ??? ???? g ?? ???? ???? ?????.
?"? ????? ????? ??, ????? ???? ???? ????
????? ?????? ??? ????? ?????? ??
32????? ???? Skip/count
???
??? suffix link ????? ?????
????? ???? ?????????, ??? ???? ?????, ????? ??
??? ??? ????? ???? ???? ?????? ??
????
?? ???? skip/count , ?? ???? ????????? ?????
???
?????
????????? ???? ?????? ? ???.
????
?? ??? ?????? ?? ??? ????????? ? - , ??
?????? ?? ?? ????? ?????? ?? ??? ???????.
33??????
- ????? ?????? ??? ????, ?? ??? 3 ?? ?????? ?????
?????? ? j, ??? ??? ????? ??? ??? ??????? ??????
????? ???? . - ????? ???? ??? ???? ???.
- ?????, ?? ???? ????? ????????? ???? ??? ???,
????? ?? ?????? j, ??? ??? ?? ???? ??? ?? ???
????? ???? ???. - ?????? ???? ???, ??? ??????? ????? ???? ?? ???
?????? ????? ???? ?????? ???? ????? ?? ?????.
34????? ????????? ?????? ???????
- ???? ?? ???? ???? ?????? ??????? ??? 3 ?? ??????
- ????? ???? ?????? ??? ????? ???? 1 ??? ??? ????,
???? ?? ???? ???? ?? ?"? ????? ??? ???? ???????
???? e, ???? ????? ???? ?? ???? . - ????? "e" ??????? ??? ???? ??????? ????, ????
???? ???????? ????.
35????? ??????
- ?? ???? ?????? ????? ?? ?????? ???? 1 ?? 2. ??
???? ? - j ?? ?????? ??????? ????? ??, ??? ??????
??? ????? ??? 2 ????? ??? ???, ???? ????? ?? j
??? (?? ???? ??????). . ???? ???, ?????
???? ?? ?? ??????? ?-1 ??? j , ?? ????? ?????
????? ???? 1, ??? ??????? ???????? ?????? ??????
???? j1.
36Single phase algorithm
- Begin
- Explicitly compute successive extensions starting
at pointer j until reaching the first extension
where rule 3 applies or until all extensions are
done in this phase. - When do rule 2, put j to point on the new leaf
- Increment index e by 1.
- end
37??? ????? ?? ????????? ??????
- ???? ????????? ?? Ukkonen ???? ???? ????? O(n)
- ??????? ??????? ??? ??????? (??? 1 ???? 3) ?? ??
???? ?????? O(1) ???, ???? ?????? O(n) ?????
????????? ????. ??? ?? ???? ??????? ???? 1 ???
???? ???? ????. ?? ???? ? j ?? ??????? ?? ??????
??????? ??????? ???, ?????? ? j ??? ?????? ?????
????, ??? ???? ??? ??? ?? ??? ????? ??????.
?????? ??? n ?????, ? j ???? ?? n, ????
?????????? ???? ????? ?? ???? ??? ????? 2n
?????? ???????. ?? ??? ?????? ?? ??? ?????? ????
??? ????, ???? ???? ?? ????? ??????, ??? ????
????? ? - O(n) ????? ?? ?????????.
38????? ????? ??????
Sabcdefabcuvw
1 2 3 4 5 6 7 8 9 10 11 12
1,3
2,3
10,12
4,6
10,12
4,6