Question: Once the suffix array is constructed, the short routine shown in Figure 12.50 can be invoked from Figure 12.32 to create the longest common prefix

Once the suffix array is constructed, the short routine shown in Figure 12.50 can be invoked from Figure 12.32 to create the longest common prefix array.
a. In the code, what does rank[i] represent?
b. Suppose that LCP[rank[i] ] = h. Show that LCP[rank[i+1] ] ‰¥ h ˆ’ 1.
c. Show that the algorithm in Figure 12.50 correctly computes the LCP array.
d. Prove that the algorithm in Figure 12.50 runs in linear time.
Figure 12.50 LCP array construction from suffix array
* Create the LCP array from the suffix array * @param s the input array populated from 0..N-1, with available pos N * @p

* Create the LCP array from the suffix array * @param s the input array populated from 0..N-1, with available pos N * @param sa the already-computed suffix array 0..N-1 * @param LCP the resulting LCP array 0..N-1 */ public static void makeLCPArray ( int [] s, int [ ] sa, int [] LCP ) int N = sa.length; int [] rank = new int[ N ]; 10 11 s[ N] = -1; 12 for( int i = 0; i < N; i+ ) rank[ sa[ i]] = i; 13 %3D 14 15 int h = 0; for( int i = 0; i < N; i++ ) if( rank[ 1] > 0 ) 16 17 18 { 19 int j = sa[ rank[ i] - 1 ]; 20 21 while( s[ i +h ] == s[ j + h] ) 22 %3D 23 htt; 24 LCP[ rank[ i]] = h; if( h > 0 ) 25 26 27 h--; 28 29

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a We see that for all i ranksai i Thus rank and sa are inverses of each other The sa array gives the list of suffixes in alphabetical order In other w... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (1 attachment)

Word file Icon

1486-C-S-A(575).docx

120 KBs Word File

Students Have Also Explored These Related Algorithms Questions!