<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
    "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
    <head>
        <title>Longest Common Subsequence</title>
    </head>

    <body>
        <h1>Longest Common Subsequence</h1>

        <p>
            Latest release:
                <a href="releases/lcs-0.1.tar.gz">lcs 0.1</a>.<br />
            <a href="haddock/">Haddock docs</a>.
        </p>

        <p>
            This cabal package provides a function lcs that takes two
            lists and returns a longest common sublist. For example,
            <code>lcs &quot;abcd&quot; &quot;acbd&quot;</code>
            is either <code>&quot;abd&quot;</code>
            or <code>&quot;acd&quot;</code>.
        </p>

        <p>
            The package provides a simple, stupid and (most of all) slow
            implementation that needs, for inputs of length
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mi>m</mi>
            </math>
            and
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mi>n</mi>
            </math>,
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mrow>
                    <mi>O</mi>
                    <mfenced>
                        <mrow>
                            <mi>m</mi><mo>+</mo><mi>n</mi>
                        </mrow>
                    </mfenced>
                </mrow>
            </math>
            space and
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mrow>
                    <mi>O</mi>
                    <mfenced>
                        <mrow>
                            <mfenced>
                                <mrow>
                                    <mi>m</mi><mo>+</mo><mi>n</mi>
                                </mrow>
                            </mfenced>
                            <mo>!</mo>
                        </mrow>
                    </mfenced>
                </mrow>
            </math>
            time in the worst case.
        </p>

        <p>
            It also provides an implementation of the Hunt-Szymanski LCS
            algorithm, based on that in
            &quot;String searching algorithms&quot; by
            Graham A Stephen, ISBN 981021829X.
            Given inputs <code>xs</code> and <code>ys</code> of length
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mi>m</mi>
            </math>
            and
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mi>n</mi>
            </math>
            respectively, where
            there are
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mi>r</mi>
            </math>
            pairs <code>(x, y)</code> where <code>x</code> is in
            <code>xs</code>, <code>y</code> is in <code>ys</code> and
            <code>x == y</code>, Hunt-Szymanski needs
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mrow>
                    <mi>O</mi>
                    <mfenced>
                        <mrow>
                            <mi>r</mi><mo>+</mo><mi>m</mi><mo>+</mo><mi>n</mi>
                        </mrow>
                    </mfenced>
                </mrow>
            </math>
            space and
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mrow>
                    <mi>O</mi>
                    <mfenced>
                        <mrow>
                            <mfenced>
                                <mrow>
                                    <mi>r</mi>
                                    <mo>+</mo>
                                    <mi>m</mi>
                                    <mo>+</mo>
                                    <mi>n</mi>
                                </mrow>
                            </mfenced>
                            <mo>*</mo>
                            <mrow>
                                <mi>log</mi>
                                <mfenced>
                                    <mrow>
                                        <mi>m</mi><mo>+</mo><mi>n</mi>
                                    </mrow>
                                </mfenced>
                            </mrow>
                        </mrow>
                    </mfenced>
                </mrow>
            </math>
            time. Thus this is
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mrow>
                    <mi>O</mi>
                    <mfenced>
                        <mrow>
                            <msup>
                                <mfenced>
                                    <mrow>
                                        <mi>m</mi><mo>+</mo><mi>n</mi>
                                    </mrow>
                                </mfenced>
                                <mn>2</mn>
                            </msup>
                        </mrow>
                    </mfenced>
                </mrow>
            </math>
            space and
            <math xmlns="http://www.w3.org/1998/Math/MathML">
                <mrow>
                    <mi>O</mi>
                    <mfenced>
                        <mrow>
                            <msup>
                                <mfenced>
                                    <mrow>
                                        <mi>m</mi><mo>+</mo><mi>n</mi>
                                    </mrow>
                                </mfenced>
                                <mn>2</mn>
                            </msup>
                            <mo>*</mo>
                            <mrow>
                                <mi>log</mi>
                                <mfenced>
                                    <mrow>
                                        <mi>m</mi><mo>+</mo><mi>n</mi>
                                    </mrow>
                                </mfenced>
                            </mrow>
                        </mrow>
                    </mfenced>
                </mrow>
            </math>
            time in the worst case.
        </p>

        <address>Ian Lynagh - &lt;<a href="mailto:igloo@earth.li">igloo@earth.li</a>&gt;</address>
    </body>
</html>

