trekhleb / trekhleb/javascript-algorithms
`replaceChild` method in BinaryTreeNode is not correct
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 197k
- Forks
- 31k
- PR merge metrics
- No merged PRs in 30d
Description
Missing update parent. It should be
if (!nodeToReplace || !replacementNode) {
return false;
}
if (this.left && this.left === nodeToReplace) {
this.left = replacementNode;
replacementNode.parent = this;
return true;
}
if (this.right && this.right === nodeToReplace) {
this.right = replacementNode;
replacementNode.parent = this;
return true;
}
return false;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the BinaryTreeNode.replaceChild method and inspect how its left and right child links are used. Confirm that a successful replacement also updates the replacement node's parent reference, then run the relevant BinaryTreeNode tests if available and verify both child positions and failure cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100