-
-
Notifications
You must be signed in to change notification settings - Fork 48.7k
Added Python Implementation of Suffix Arrays and LCP Arrays #12170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This code file provides an implementation of Suffix Arrays and Longest Common Prefix (LCP) Arrays in Python, designed as a contribution to the open-source community during Hacktoberfest 2024. Overview: A suffix array is an essential data structure used in many string-processing algorithms. It provides an efficient way to store and sort all possible suffixes of a given string. This project also includes the construction of the LCP array, which records the lengths of the longest common prefixes between consecutive suffixes in the sorted suffix array. Together, these two arrays form the backbone of many algorithms in text processing and pattern matching. Key Features: Suffix Array Construction: A suffix array is built by sorting all suffixes of the input string in lexicographical order and storing their starting indices. LCP Array Construction: The LCP array is computed using an efficient algorithm that compares consecutive suffixes from the suffix array and records the length of their common prefixes. Optimized Approach: The approach used in this implementation ensures efficient computation of both suffix and LCP arrays with a linear-time construction of the LCP array following the suffix sorting. User-friendly Display: The program clearly displays both the suffix and LCP arrays, allowing users to easily visualize and understand the results for any given input string. Why this Contribution? As part of Hacktoberfest 2024, I wanted to contribute something that could be useful for developers and researchers working with text-processing algorithms. This implementation not only helps in better understanding of basic string operations but also serves as a building block for more complex algorithms in fields like bioinformatics, data compression, and natural language processing. Example Output: For the input string "banana", the program generates the following arrays: Suffix Array: [5, 3, 1, 0, 4, 2] (indicating the starting indices of the lexicographically sorted suffixes) LCP Array: [0, 1, 3, 0, 0, 2] (showing the lengths of the longest common prefixes between consecutive suffixes) Why Suffix Arrays and LCP Arrays Matter: Text Searching: Suffix arrays are used in algorithms for fast substring searching, making them invaluable in tasks like searching through large databases or text files. Repetitive Patterns: The LCP array highlights repeated patterns within the text, which can be useful in applications like data compression, where redundancy needs to be minimized. Bioinformatics: These arrays are critical for genome sequencing and alignment algorithms, where comparing large sequences efficiently is necessary. How to Use: This implementation is easy to run with any input string, and users can quickly get a clear visualization of the suffix and LCP arrays. Whether you're new to algorithms or looking to expand your toolkit for more advanced string manipulation tasks, this project provides a solid foundation.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request provides an implementation of Suffix Arrays and Longest Common Prefix (LCP) Arrays in Python, contributing to the open-source community as part of Hacktoberfest 2024.
Overview:
A suffix array is a fundamental data structure used in various text processing algorithms. This project implements:
Key Features:
Why this Contribution?
As part of Hacktoberfest 2024, this contribution aims to assist developers working with text-processing algorithms. This implementation serves as a foundation for more advanced algorithms in fields such as bioinformatics, data compression, and natural language processing.
Example Output:
For the input string
"banana"
, the program generates:[5, 3, 1, 0, 4, 2]
[0, 1, 3, 0, 0, 2]
Why Suffix Arrays and LCP Arrays Matter:
References:
For more information on suffix arrays and LCP arrays:
Describe your change:
Checklist: