Repository navigation
Conversation
…ed one
After deleting the only child of a node that ends a word, delete returned True and the parent dropped that node, so insert('a'), insert('ab'), delete('ab') made find('a') False. Keep a node that still ends a word.
mindaugl
approved these changes
Nov 23, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
data_structures/trie/trie.py::TrieNode.deleteremoved a word that is a prefix of the deleted one. After deleting the only child of a node that itself ends a word,_deletereturnedTruebecause the node had no children left, and the parent dropped it. Soinsert("a"),insert("ab"),delete("ab")leftfind("a")asFalse. The node is now reported as removable only when it has no children and does not end a word.I added a doctest for it (it fails on
master); the added doctest is the regression evidence for this one function, so I kept it in the same PR. Against a Python set of words, 1500 random runs of inserts, deletes and finds overa,b,c(two seeds) agree after the change; onmasterthe same runs found 20 wrongfindresults.ruff check,ruff format --checkandpython -m doctestpass.Written with the help of Claude Code (Claude Sonnet 5.5).
Checklist