Skip to content

Trie implementation#111

Merged
sachinarora707 merged 6 commits into
TheAlgorithms:masterfrom
JavonDavis:trie-implementation
Sep 10, 2017
Merged

Trie implementation#111
sachinarora707 merged 6 commits into
TheAlgorithms:masterfrom
JavonDavis:trie-implementation

Conversation

@JavonDavis

Copy link
Copy Markdown
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
Comment thread data_structures/Trie/Trie.py Outdated
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
Copy Markdown
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
Copy Markdown
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

Comment thread data_structures/Trie/Trie.py Outdated
def test():
words = []
# Load words from text file into Trie
with open("../../other/Dictionary.txt", "r") as ins:

Copy link
Copy Markdown
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
Copy Markdown
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?

@sachinarora707 sachinarora707 left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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