Skip to main content

A collection of LCS algorithms in Python

Project description

LCS Algorithms Library

A Python library implementing multiple algorithms for computing the Longest Common Subsequence (LCS) between sequences (strings), including multi-sequence LCS.

Features

  • Dynamic Programming LCS
    • lcsdp(sequence1, sequence2) — Finds the LCS of two sequences using dynamic programming.
  • Multiple Sequence LCS (Dynamic Programming)
    • mlcsdp(sequences) — Finds the LCS among multiple sequences using dynamic programming.
  • Dominant Point Approach
    • mlcsdpa(sequences, Sigma) — Finds the multi-sequence LCS using the dominant point approach.
  • Parallel Algorithm
    • RAA(sequences, Sigma) — Parallel multi-sequence LCS computation.
  • Redundancy Reduced Dominant Point Approach
    • rrmlcs(sequences, Sigma) — Optimized multi-sequence LCS using redundancy reduction.
  • Pairwise Solution (1997)
    • TA(sequences) — Pairwise multi-sequence LCS based on a 1997 published method.
  • Tournament Based Approach
    • TBA(s1, s2) — Tournament method for LCS of two sequences.

Installation

pip install lcs

Usage

from lcs import lcsdp, mlcsdp, mlcsdpa, RAA, rrmlcs, TA, TBA

# Example: LCS of two sequences
s1 = "AGGTAB"
s2 = "GXTXAYB"
print(lcsdp(s1, s2))

# Example: Multiple sequences
sequences = ["AGGTAB", "GXTXAYB", "GTAB"]
print(mlcsdp(sequences))

2. mlcsdp(sequences)

Dynamic Programming-based Multiple Sequence LCS.

Example:

from lcs_algorithms import mlcsdp
seqs = ["ABCBDAB", "BDCAB", "BCAB"]
result = mlcsdp(seqs)
print(result)  # Output: "BCAB"

2. mlcsdp(sequences)

Dynamic Programming-based Multiple Sequence LCS.

Example:

from lcs_algorithms import mlcsdp
seqs = ["ABCBDAB", "BDCAB", "BCAB"]
result = mlcsdp(seqs)
print(result)  # Output: "BCAB"

2. mlcsdp(sequences)

Dynamic Programming-based Multiple Sequence LCS.

Example:

from lcs_algorithms import mlcsdp
seqs = ["ABCBDAB", "BDCAB", "BCAB"]
result = mlcsdp(seqs)
print(result)  # Output: "BCAB"

3. mlcsdpa(sequences, Sigma)

Dominant Point Approach for multiple sequence LCS. Sigma is the alphabet set of all possible characters in the sequences.

Example:

from lcs_algorithms import mlcsdpa
Sigma = {'A', 'B', 'C', 'D'}
seqs = ["ABCBDAB", "BDCAB", "BCAB"]
result = mlcsdpa(seqs, Sigma)
print(result)

4. RAA(sequences, Sigma)

Parallel Algorithm for multiple sequence LCS computation.

Example:

from lcs_algorithms import RAA
Sigma = {'A', 'B', 'C', 'D'}
seqs = ["ABCBDAB", "BDCAB", "BCAB"]
result = RAA(seqs, Sigma)
print(result)

5. rrmlcs(sequences, Sigma)

Redundancy-Reduced Dominant Point based algorithm.

Example:

from lcs_algorithms import rrmlcs
Sigma = {'A', 'B', 'C', 'D'}
seqs = ["ABCBDAB", "BDCAB", "BCAB"]
result = rrmlcs(seqs, Sigma)
print(result)

6. TA(sequences)

Pairwise LCS Solution (1997 algorithm).

Example:

from lcs_algorithms import TA
seqs = ["ABCBDAB", "BDCAB"]
result = TA(seqs)
print(result)

7. TBA(s1, s2)

Tournament-Based Algorithm for LCS of two sequences.

Example:

from lcs_algorithms import TBA
result = TBA("ABCBDAB", "BDCAB")
print(result)

Installation

You can install via:

pip install lcs_algorithms

or you can clone and install it via:

git clone https://github.com/zeshanalvi/lcs_algorithms.git
cd lcs_algorithms
pip install .

Parameters

  • sequence1, sequence2, s1, s2: Strings representing sequences.
  • sequences: List of strings (multiple sequences).
  • Sigma: Set of symbols (alphabet) used for dominant point and parallel algorithms.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lcs_algorithms-0.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lcs_algorithms-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file lcs_algorithms-0.1.1.tar.gz.

File metadata

  • Download URL: lcs_algorithms-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for lcs_algorithms-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ac8874ab5bc70b957506946893ae8330d0586d0d71dac442bf3a6aa6724574ce
MD5 93ed87d78a11ed15acb0915fd9dbf91b
BLAKE2b-256 12eec21e1b8a6ba39f1dc92a04c09375953f25980525dbfa40f97166f3cf4fa2

See more details on using hashes here.

File details

Details for the file lcs_algorithms-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: lcs_algorithms-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for lcs_algorithms-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a938794fbe23d45e6bc7f1553a44ddb5543386ecd926fb8a0ed9566e214f570e
MD5 ec24026082ff78d540a3b1619d730c44
BLAKE2b-256 abf2ee3f90e99f2ce31701c3864834f5272ccf46369e871754f1adfc5bbeb315

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page