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

Add Trie (Prefix Tree) Data Structure Implementation #614

Open
ahamed-ali-git opened this issue Mar 9, 2025 · 0 comments · May be fixed by #615
Open

Add Trie (Prefix Tree) Data Structure Implementation #614

ahamed-ali-git opened this issue Mar 9, 2025 · 0 comments · May be fixed by #615

Comments

@ahamed-ali-git
Copy link

Description:
Proposal: Trie Data Structure
I'd like to contribute a Trie (Prefix Tree) implementation to PyDataStructs - a powerful and efficient data structure that is currently missing from the collection.

What is a Trie?
A Trie is a specialized tree-based data structure that excels at storing and retrieving strings with common prefixes. It offers O(L) lookup time where L is the length of the string, making it significantly faster than hash tables for certain operations.

Why add it to PyDataStructs?

Completes the collection - Tries are fundamental data structures taught in CS curricula
Practical applications - Used in autocomplete, spell-checkers, IP routing, etc.
Educational value - Demonstrates tree-based prefix storage concepts

Proposed Implementation:
pythonCopyclass Trie:
def init(self)
def insert(self, word) # Add a word to the trie
def search(self, word) # Check if word exists in trie
def starts_with(self, prefix) # Find words with a given prefix
def delete(self, word) # Remove a word from the trie

Testing Strategy:

Unit tests covering all operations
Edge cases (empty strings, non-existing words)
Performance benchmarking against alternative methods

Real-world Use Cases:

Autocomplete systems - Quickly find all words with a given prefix
Spell checkers - Efficient dictionary implementation
IP routing tables - Longest prefix matching
Word games - Fast word validation

I'm excited to work on this implementation and would appreciate any feedback on the proposed API or implementation details!

I'm following the project's contribution guidelines and plan to thoroughly test the implementation. I'd be happy to take on this task if approved.

@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 a pull request may close this issue.

1 participant