trekhleb / trekhleb/javascript-algorithms
AVL remove need recursive from removeNode
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 197k
- Forks
- 31k
- PR merge metrics
- No merged PRs in 30d
Description
Add Test:
it('AvlTree remove node', () => {
const tree = new AvlTree();
tree.insert(9);
tree.insert(5);
tree.insert(12);
tree.insert(3);
tree.insert(7);
tree.insert(11);
tree.insert(13);
tree.insert(2);
tree.insert(4);
tree.insert(6);
tree.insert(8);
tree.insert(10);
expect(tree.toString()).toBe('2,3,4,5,6,7,8,9,10,11,12,13');
expect(tree.toString2()).toBe('9,5,3,2,4,7,6,8,12,11,10,13'); // toString2 is preOrder
tree.insert(1);
expect(tree.toString2()).toBe('9,5,3,2,1,4,7,6,8,12,11,10,13');
tree.insert(0);
expect(tree.toString2()).toBe('9,5,3,1,0,2,4,7,6,8,12,11,10,13');
tree.remove(13);
expect(tree.toString2()).toBe('9,5,3,1,0,2,4,7,6,8,12,11,10'); // now
expect(tree.toString2()).toBe('5,3,1,0,2,4,9,7,6,8,11,10,12'); // correct
});
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 with the AvlTree remove and removeNode implementation, then locate the AVL tree test suite. Run the supplied insertion and removal scenario and compare the in-order and pre-order results, resolving the expected post-removal traversal. Done means the test passes with the corrected tree structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100