Skip to content
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

Implemented Suffix Tree Data Structure #11554

Merged

Conversation

Ramy-Badr-Ahmed
Copy link
Member

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed commented Sep 7, 2024

Describe your change:

This pull request adds an implementation of the Suffix Tree data structure along with related functionalities, such as pattern searches.

Definition: The Suffix Tree is a compressed trie of all the suffixes of a given text used for for substring search and various other string-processing operations. (URL: Suffix Tree).

Implementation Details:

  • suffix_tree_node.py: Defines the SuffixTreeNode class, representing nodes in the suffix tree.
  • build_suffix_tree.py: Builds a suffix tree from the given text and apply pattern searche for a pattern in the built suffix tree.

Example Usage:

  • example_usage.py: Demonstrates how to use the Suffix Tree implementation with a predefined text and searches for various patterns.

Unit Tests:

  • test_suffix_tree.py: Validates the correctness of the Suffix Tree implementation, including tests for building the tree and searching for patterns.

Reference

Data Structures and Algorithms in C++, 2nd Edition

Ramy-Badr-Ahmed and others added 30 commits August 28, 2024 13:09
…into feature/kd-tree-implementation

# Conflicts:
#	data_structures/kd_tree/nearest_neighbour_search.py
…into feature/kd-tree-implementation

# Conflicts:
#	data_structures/kd_tree/tests/test_kdtree.py
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Sep 7, 2024
Copy link
Member Author

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. All checks have passed. 👍🏻

Hi, @cclauss & @imSanko: Looking forward for your review 👋

Copy link
Contributor

@imSanko imSanko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me, wait for the merge!

@Ramy-Badr-Ahmed

This comment was marked as outdated.

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed changed the title Suffix Tree Data Structure Implementation Implemented Suffix Tree Data Structure Sep 25, 2024
Ramy-Badr-Ahmed

This comment was marked as outdated.

Copy link
Member Author

@Ramy-Badr-Ahmed Ramy-Badr-Ahmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added Doc blocks to the rest of my files requesting mentioning me for bugs/corrections.
All checks have passed 👍

build
ruff
pre-commit

@cclauss cclauss merged commit 976e385 into TheAlgorithms:master Sep 28, 2024
3 checks passed
cclauss added a commit to cclauss/Python that referenced this pull request Sep 30, 2024
* Implemented KD-Tree Data Structure

* Implemented KD-Tree Data Structure. updated DIRECTORY.md.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Create __init__.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Replaced legacy `np.random.rand` call with `np.random.Generator` in kd_tree/example_usage.py

* Replaced legacy `np.random.rand` call with `np.random.Generator` in kd_tree/hypercube_points.py

* added typehints and docstrings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* docstring for search()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added tests. Updated docstrings/typehints

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updated tests and used | for type annotations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* E501 for build_kdtree.py, hypercube_points.py, nearest_neighbour_search.py

* I001 for example_usage.py and test_kdtree.py

* I001 for example_usage.py and test_kdtree.py

* Update data_structures/kd_tree/build_kdtree.py

Co-authored-by: Christian Clauss <[email protected]>

* Update data_structures/kd_tree/example/hypercube_points.py

Co-authored-by: Christian Clauss <[email protected]>

* Update data_structures/kd_tree/example/hypercube_points.py

Co-authored-by: Christian Clauss <[email protected]>

* Added new test cases requested in Review. Refactored the test_build_kdtree() to include various checks.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considered ruff errors

* Considered ruff errors

* Apply suggestions from code review

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update kd_node.py

* imported annotations from __future__

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Implementation of the suffix tree data structure

* Adding data to DIRECTORY.md

* Minor file renaming

* minor correction

* renaming in DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-1

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-2

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-3

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-4

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-5

* Implemented Suffix Tree Data Structure.
Added some comments to my files in TheAlgorithms#11532, TheAlgorithms#11554.

* updating DIRECTORY.md

* Implemented Suffix Tree Data Structure.
Added some comments to my files in TheAlgorithms#11532, TheAlgorithms#11554.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Ramy-Badr-Ahmed <[email protected]>
cclauss added a commit to cclauss/Python that referenced this pull request Sep 30, 2024
* Implemented KD-Tree Data Structure

* Implemented KD-Tree Data Structure. updated DIRECTORY.md.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Create __init__.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Replaced legacy `np.random.rand` call with `np.random.Generator` in kd_tree/example_usage.py

* Replaced legacy `np.random.rand` call with `np.random.Generator` in kd_tree/hypercube_points.py

* added typehints and docstrings

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* docstring for search()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added tests. Updated docstrings/typehints

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updated tests and used | for type annotations

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* E501 for build_kdtree.py, hypercube_points.py, nearest_neighbour_search.py

* I001 for example_usage.py and test_kdtree.py

* I001 for example_usage.py and test_kdtree.py

* Update data_structures/kd_tree/build_kdtree.py

Co-authored-by: Christian Clauss <[email protected]>

* Update data_structures/kd_tree/example/hypercube_points.py

Co-authored-by: Christian Clauss <[email protected]>

* Update data_structures/kd_tree/example/hypercube_points.py

Co-authored-by: Christian Clauss <[email protected]>

* Added new test cases requested in Review. Refactored the test_build_kdtree() to include various checks.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considered ruff errors

* Considered ruff errors

* Apply suggestions from code review

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update kd_node.py

* imported annotations from __future__

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Implementation of the suffix tree data structure

* Adding data to DIRECTORY.md

* Minor file renaming

* minor correction

* renaming in DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-1

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-2

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-3

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-4

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Considering ruff part-5

* Implemented Suffix Tree Data Structure.
Added some comments to my files in TheAlgorithms#11532, TheAlgorithms#11554.

* updating DIRECTORY.md

* Implemented Suffix Tree Data Structure.
Added some comments to my files in TheAlgorithms#11532, TheAlgorithms#11554.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <[email protected]>
Co-authored-by: Ramy-Badr-Ahmed <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants