Skip to content

Conversation

appleJax
Copy link
Contributor

This PR adds the ability to delete words from the Trie data structure.

NOTE - when deleting a word:

  • sets trieNode.isCompleteWord to false for the last character in the word
  • deletes trieNodes in depth-first order (last character -> first character)
  • does NOT delete trieNodes if they have children
  • does NOT delete trieNodes if trieNode.isCompleteWord === true (this is to prevent substring words from being deleted)

Example usage:

const trie = new Trie();
trie.addWord('carpet');
trie.addWord('car');

trie.deleteWord('carpet');

trie.doesWordExist('carpet'); // returns false
trie.doesWordExist('car'); // returns true

Issue: #108
Refactored From PR: #168

@appleJax appleJax mentioned this pull request Aug 27, 2018
@trekhleb trekhleb changed the base branch from master to trie-word-remove August 27, 2018 12:31
@trekhleb
Copy link
Owner

@appleJax thank you for pull request!

@trekhleb trekhleb merged commit d25eff4 into trekhleb:trie-word-remove Aug 27, 2018
@appleJax appleJax deleted the feature/Trie.deleteWord branch August 28, 2018 04:45
harshes53 pushed a commit to harshes53/javascript-algorithms that referenced this pull request Dec 6, 2018
shoredata pushed a commit to shoredata/javascript-algorithms that referenced this pull request Mar 28, 2019
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.

2 participants