<p>You can't find LCP of any two suffixes by simply calculating  the  minimum of the lcp's of all pairs of adjacent suffixes between them on the array.</p>

<p>We can calculate the LCPs of any suffixes (i,j)
with the Help of Following :</p>

<pre><code>LCP(suffix i,suffix j)=LCP[RMQ(i + 1; j)]  
</code></pre>

<p>Also Note <code>(i&lt;j)</code> as <code>LCP (suff i,suff j)</code>  may not necessarly equal <code>LCP (Suff j,suff i)</code>.
RMQ is <strong>Range Minimum Query</strong>  .</p>

<p>Page 3 of this <a href="http://arxiv.org/pdf/1012.4263.pdf" rel="nofollow">paper</a>.</p>

<pre><code>Details:
</code></pre>

<p><strong>Step 1:</strong>
First Calculate LCP of Adjacents /consecutive Suffix Pairs .</p>

<p>n= Length of string.</p>

<p>suffixArray[] is Suffix array.</p>

<pre><code>void calculateadjacentsuffixes(int n)
{
    for (int i=0; i&lt;n; ++i) Rank[suffixArray[i]] = i;
    Height[0] = 0;
    for (int i=0, h=0; i&lt;n; ++i)
    {
        if (Rank[i] &gt; 0)
        {
            int j = suffixArray[Rank[i]-1];
            while (i + h &lt; n &amp;&amp; j + h &lt; n &amp;&amp; str[i+h] == str[j+h])
            {
                h++;
            }
            Height[Rank[i]] = h;
            if (h &gt; 0) h--;
        }
    }
}
</code></pre>

<p><strong>Note: Height[i]=LCPs of (Suffix   i-1 ,suffix  i) ie. Height array contains LCP of adjacent suffix.</strong></p>

<p><strong>Step 2:</strong></p>

<p>Calculate LCP of Any two suffixes i,j using RMQ concept.
 RMQ pre-compute function:</p>

<pre><code>void preprocesses(int N)
{
    int i, j;

    //initialize M for the intervals with length 1
    for (i = 0; i &lt; N; i++)
        M[i][0] = i;

    //compute values from smaller to bigger intervals
    for (j = 1; 1 &lt;&lt; j &lt;= N; j++)
    {
        for (i = 0; i + (1 &lt;&lt; j) - 1 &lt; N; i++)
        {
            if (Height[M[i][j - 1]] &lt; Height[M[i + (1 &lt;&lt; (j - 1))][j - 1]])
            {
                M[i][j] = M[i][j - 1];
            }
            else
            {
                M[i][j] = M[i + (1 &lt;&lt; (j - 1))][j - 1];
            }
        }
    }
}  
</code></pre>

<p>Step 3: Calculate LCP between any two Suffixes i,j</p>

<pre><code>int LCP(int i,int j)
{
    /*Make sure we send i&lt;j always */
    /* By doing this ,it resolve following
    suppose ,we send LCP(5,4) then it converts it to LCP(4,5)
    */
    if(i&gt;j)
        swap(i,j);

    /*conformation over*/

    if(i==j)
    {
        return (Length_of_str-suffixArray[i]);
    }
    else
    {
        return Height[RMQ(i+1,j)];
        //LCP(suffix i,suffix j)=LCPadj[RMQ(i + 1; j)] 
        //LCPadj=LCP of adjacent suffix =Height.
    }
}
</code></pre>

<p>Where RMQ function is:</p>

<pre><code>int RMQ(int i,int j)
{
    int k=log((double)(j-i+1))/log((double)2);
    int vv= j-(1&lt;&lt;k)+1 ;
    if(Height[M[i][k]]&lt;=Height[ M[vv][ k] ])
        return M[i][k];
    else
        return M[ vv ][ k];
}
</code></pre>

<p>Refer <strong><a href="http://community.topcoder.com/tc?module=Static&amp;d1=tutorials&amp;d2=lowestCommonAncestor" rel="nofollow">Topcoder tutorials</a></strong> for RMQ.</p>

<p>You can check the complete implementation in C++ at my <strong><a href="http://riteshkumarnitw.webs.com/mycoderepository.htm" rel="nofollow">blog</a></strong>.</p>
Longest Common Prefix property
<p>I was going through suffix array and its use to compute longest common prefix of two suffixes.</p>

<p>The source says: </p>

<blockquote>
  <p>"The lcp between two suffixes is the minimum of the lcp's of all pairs of adjacent suffixes between them on the array"</p>
</blockquote>

<p>i.e. <code>lcp(x,y)=min{ lcp(x,x+1),lcp(x+1,x+2),.....,lcp(y-1,y) }</code>
where x and y are two index of the string from where the two suffix of the string starts.</p>

<p>I am not convinced with the statement as in example of string <code>"abca"</code>.</p>

<p><code>lcp(1,4)=1</code> (considering 1 based indexing)</p>

<p>but if I apply the above equation then </p>

<p><code>lcp(1,4)=min{lcp(1,2),lcp(2,3),lcp(3,4)}</code></p>

<p>and I think <code>lcp(1,2)=0</code>.</p>

<p>so the answer must be <code>0</code> according to the equation.</p>

<p>Am i getting it wrong somewhere?</p>