private static String algorithmC()

in src/main/java/org/apache/commons/text/similarity/LongestCommonSubsequence.java [110:145]


    private static String algorithmC(final CharSequence left, final CharSequence right) {
        final int m = left.length();
        final int n = right.length();
        final StringBuilder out = new StringBuilder();
        if (m == 1) { // Handle trivial cases, as per the paper
            final char leftCh = left.charAt(0);
            for (int j = 0; j < n; j++) {
                if (leftCh == right.charAt(j)) {
                    out.append(leftCh);
                    break;
                }
            }
        } else if (n > 0 && m > 1) {
            final int mid = m / 2; // Find the middle point
            final CharSequence leftFirstPart = left.subSequence(0, mid);
            final CharSequence leftSecondPart = left.subSequence(mid, m);
            // Step 3 of the algorithm: two calls to Algorithm B
            final int[] l1 = algorithmB(leftFirstPart, right);
            final int[] l2 = algorithmB(reverse(leftSecondPart), reverse(right));
            // Find k, as per the Step 4 of the algorithm
            int k = 0;
            int t = 0;
            for (int j = 0; j <= n; j++) {
                final int s = l1[j] + l2[n - j];
                if (t < s) {
                    t = s;
                    k = j;
                }
            }
            // Step 5: solve simpler problems, recursively
            out.append(algorithmC(leftFirstPart, right.subSequence(0, k)));
            out.append(algorithmC(leftSecondPart, right.subSequence(k, n)));
        }

        return out.toString();
    }