8000 GitHub - VantorreWannes/cos_lcs: My own heuristic LCS algorithm
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

VantorreWannes/cos_lcs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cos_lcs

A heuristic algorithm for approximating the Longest Common Subsequence (LCS) proble 824C m.

Overview

cos_lcs stands for Closest Offset Sum LCS. It is a heuristic algorithm designed to approximate the Longest Common Subsequence between two sequences. While it may not consistently find the full LCS, it provides a fast approximation with linear time complexity, making it suitable for large inputs where classical algorithms become impractical.

Algorithm Details

The algorithm implementation can be found in src/cos_lcs.rs. Unlike the classical dynamic programming approach for LCS, which has a time complexity of O(N×M), cos_lcs offers a linear time approximation. Although it does not guarantee the longest possible common subsequence, it ensures that any subsequence it finds is a valid common subsequence of the input sequences.

Time Complexity

  • Time Complexity: O(N + M)

Approximation Factor

In the context of LCS approximation (a maximization problem), the approximation factor of cos_lcs is α = 0.8. This means that the length of the subsequence found by the algorithm is at least 80% of the optimal LCS length.

Benchmarks and Testing

You can adjust the input lengths for most tests and benchmarks in this repository. Note that input lengths over 10,000 for single tests or 3,000 for benchmarks may result in long wait times if the classical LCS algorithm is involved, as in benches/slow_lcs.rs.

Running Benchmarks

Run benchmarks with:

cargo bench

Adjust the LENGTH constant in benches/cos_lcs.rs and benches/slow_lcs.rs to modify input lengths.

Testing Accuracy

Test the accuracy of the algorithm by running:

cargo test test_accuracy -- --show-output

The input length for the tests can also be controlled via the LENGTH constant in the test files.

Related Work

This project was compared to the following sources:

Building from Source

  1. Install the stable branch of Rust using Rustup.

  2. Clone the repository and navigate to the project root directory.

  3. Compile the program:

    cargo build

License

[Todo]

Contributing

[Todo]

About

My own heuristic LCS algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0