LCP algorithm