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 Algorithm Implementation #86

Closed
wants to merge 3 commits into from

Conversation

staging-devin-ai-integration[bot]
Copy link

@staging-devin-ai-integration staging-devin-ai-integration bot commented Aug 23, 2024

Trie Algorithm Implementation

This pull request implements a Trie data structure in Python for efficient prefix-based word storage and retrieval. The implementation includes the following key features:

Features

  • TrieNode class for representing individual nodes in the trie
  • Trie class with the following methods:
    • insert(word: str) -> None: Insert a word into the trie
    • search(word: str) -> bool: Search for a word in the trie
    • starts_with(prefix: str) -> bool: Check if any word in the trie starts with the given prefix
    • delete(word: str) -> bool: Remove a word from the trie if it exists

Implementation Details

  • Time complexity for all operations: O(m), where m is the length of the word/prefix
  • Space complexity: O(n * m), where n is the number of words and m is the average length of the words
  • Handles edge cases such as empty strings, case sensitivity, and non-alphabetic characters

Testing

A comprehensive test suite is included to verify the functionality of the Trie class, covering various scenarios and edge cases.

Additional Information

For more details about this implementation, please visit:
https://staging.itsdev.in/devin/08fe1f5df7204b35940d76f0c6362a97

This implementation provides an efficient solution for prefix-based word storage and retrieval, which is the primary use case for a trie data structure.

This Devin run was requested by Federico.

If you have any feedback, you can leave comments in the PR and I'll address them in the app!

@@ -0,0 +1,68 @@
# Trie Algorithm Implementation Plan
Copy link
Owner

Choose a reason for hiding this comment

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

add a funny story under this line


## 1. Structure
- Create a `TrieNode` class:
- `children`: A dictionary to store child nodes (key: character, value: TrieNode)
Copy link
Owner

Choose a reason for hiding this comment

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

all caps

Copy link
Author

Closing due to inactivity.

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.

1 participant