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

Implement Trie (Prefix Tree) Data Structure in PyDataStructs #615

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ahamed-ali-git
Copy link

References to Other Issues or PRs or Relevant Literature
Fixes #614

This PR introduces a Trie (Prefix Tree) data structure to the PyDataStructs library. Tries are fundamental data structures widely used in applications such as autocomplete, spell checkers, and IP routing.

Brief Description of What is Fixed or Changed
This PR adds:

Trie Implementation (pydatastructs/trees/trie.py)

TrieNode class for individual nodes
Trie class with essential methods:
insert(word): Inserts a word into the Trie
search(word): Checks if a word exists in the Trie
starts_with(prefix): Determines if any word starts with a given prefix
delete(word): Removes a word from the Trie
_get_node(prefix): A helper method for efficient prefix search
Tests (tests/trees/test_trie.py)

Unit tests covering all functionalities
Edge cases (empty strings, deletion of non-existent words)
Validations against expected Trie behavior
Project Structure Updates

Updated pydatastructs/trees/init.py to expose Trie
Added tests/init.py if missing
Other Comments
The Trie follows the coding style of PyDataStructs
The implementation is well-documented with NumPy-style docstrings and examples

Tests can be run using:

python -m pytest --doctest-modules --cov=./ --cov-report=html
Code coverage has been verified

Looking forward to feedback from the maintainers! @Kishan-Ved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Trie (Prefix Tree) Data Structure Implementation
1 participant