Skip to content

Trie implementation #111

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

Merged
merged 6 commits into from
Sep 10, 2017

Conversation

JavonDavis
Copy link
Contributor

Regarding #105 I've worked on a Trie implementation using a dict

* Basic definition of Trie in comments at the top of the file
* Defined Trie class and method signatures.
* Finished function to insert a word into Trie
* Finished function to find a word in the Trie
* Added Test functions with Assertions
@dynamitechetan dynamitechetan added the awaiting reviews This PR is ready to be reviewed label Sep 10, 2017
making it impractical in practice. It however provides O(max(search_string, length of longest word)) lookup
time making it an optimal approach when space is not an issue.

This implementation assumes the character $ is not in any of the words. This character is used in the implementation
Copy link
Member

Choose a reason for hiding this comment

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

Can you please find some way to achieve the desired result without setting a predefined character? An algorithm is supposed to consider all test cases in mind. Good job though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, no prob! I'll work on it

def test():
words = []
# Load words from text file into Trie
with open("../../other/Dictionary.txt", "r") as ins:
Copy link
Member

Choose a reason for hiding this comment

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

Can you please switch this with a string sample? This would make it easier for the user to run and test the code. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the sample I had in 9a52167 ok?

Copy link
Contributor

@sachinarora707 sachinarora707 left a comment

Choose a reason for hiding this comment

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

Taking input from a file makes it difficult to test the algorithm. Please get input from user or else, add a sample input.

* No longer reading from file but instead provided simple sample input for easier testing
@JavonDavis
Copy link
Contributor Author

@sachinarora707 @r0hit-gupta I'm now using a boolean attribute instead of the $ and provided a list of strings instead of reading from the file

@r0hit-gupta
Copy link
Member

@JavonDavis great job. Please delete the empty __init__.py file and you are good to go.

@sachinarora707 sachinarora707 merged commit 1bed547 into TheAlgorithms:master Sep 10, 2017
@JavonDavis JavonDavis deleted the trie-implementation branch September 11, 2017 04:57
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.

4 participants