Content deleted Content added
m Open access bot: hdl, doi added to citation with #oabot. |
Enervation (talk | contribs) →Definition: Change Example to use 1-based indexing to match definition section |
||
Line 35:
== Definition ==
Let <math>A</math> be the [[suffix array]] of the string <math>S=s_1,s_2,\ldots
Let <math>\operatorname{lcp}(v,w)</math> denote the length of the longest common prefix between two strings <math>v</math> and <math>w</math>. Then the LCP array <math>H[1,n]</math> is an integer array of size <math>n</math> such that <math>H[1]</math> is undefined and <math>H[i]=\operatorname{lcp}(S[A[i-1],n],S[A[i],n])</math> for every <math>1<i\leq n</math>. Thus <math>H[i]</math> stores the length of longest common prefix of the
* Suffix array: Represents the lexicographic rank of each suffix of an array.▼
* LCP array: Contains the maximum length prefix match between two consecutive suffixes, after they are sorted lexicographically.▼
== Example ==
Line 45 ⟶ 50:
|-
! {{left header}} | i
|-
! {{left header}} | S[i]
Line 53 ⟶ 58:
{| class="wikitable"
! {{left header}} | i
|-
! {{left header}} | A[i]
|
|}
{| class="wikitable"
! {{left header}} | i
|-
! {{left header}} | A[i]
|
|-
! {{left header}} | S[A[i], n][1]
| $ || a || a || a || b || n || n
|-
! {{left header}} | S[A[i], n][2]
| || $ || n || n || a || a || a
|-
! {{left header}} | S[A[i], n][3]
| || || a || a || n || $ || n
|-
! {{left header}} | S[A[i], n][4]
| || || $ || n || a || || a
|-
! {{left header}} | S[A[i], n][5]
| || || || a || n || || $
|-
! {{left header}} | S[A[i], n][6]
| || || || $ || a || ||
|-
! {{left header}} | S[A[i], n][7]
| || || || || $ || ||
Line 96 ⟶ 101:
|-
! {{left header}} | i
|-
! {{left header}} | H[i]
|
|}
So, for example, <math>H[3]=3</math> is the length of the longest common prefix <math>ana</math> shared by the suffixes <math> A[
▲== Difference between suffix array and LCP array ==
▲Suffix array: Represents the lexicographic rank of each suffix of an array.
▲LCP array: Contains the maximum length prefix match between two consecutive suffixes, after they are sorted lexicographically.
== LCP array usage in finding the number of occurrences of a pattern ==
|