Repository navigation
fix delete - #12
Open
cscott wants to merge 2 commits into
Open
fix delete#12cscott wants to merge 2 commits into
cscott wants to merge 2 commits into
Conversation
cscott
commented
Oct 15, 2026
- fix: recompute the new subtree root max in rotateRight()
- fix: make deleteFixup() match CLRS RB-DELETE-FIXUP
After a right rotation the node that moved up ($x) must have its max recomputed, but the code recomputed $y a second time instead. The stale max on the new subtree root makes findIntersections() prune subtrees that do contain matches. Insert-only workloads mostly mask this because insert() re-walks the path to the root afterwards; the delete fix-up does not.
Two deviations from the textbook algorithm corrupted the tree on removal: * Case 2 must only apply when *both* of the sibling's children are black; the code tested only the near child. * After the case-3 rotation the sibling must be re-read from the parent (w = x.p.right / x.p.left); the code kept using the old sibling. Either one breaks the black-height or red-red invariant, after which later removals dereference the nil sentinel's (null) children and throw a TypeError, and queries return wrong results. Add a randomized test that checks findIntersections() and getSize() against a brute-force list across a mix of inserts and removals. On the previous code 45 of the 50 seeds fail.
Owner
|
Thanks for the fixes! I went through both changes against CLRS and they look correct: the CI was failing for a reason unrelated to your changes: the workflow used the retired Could you rebase this branch onto the current |
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.