Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug for the remove method of BinarySearchTree #58

Merged
merged 1 commit into from
Jan 14, 2018

Conversation

zhijli
Copy link
Contributor

@zhijli zhijli commented Jan 6, 2018

Fix two bugs for the remove method:

Bug 1: When the node to be removed has two children , should remove the successor (nextLarger) node, not the right child.
For example, given a tree (A), if we remove node 2, the tree should looks like (B), but now it actually looks like (C).

         (A)                   (B)                    (C)
          8                     8                      8
         / \                   / \                    / \ 
        2   9                 3   9                  5   9        
       / \                   / \                    / \
      1   5                 1   5                  1   6
         / \                     \                    /   
        3   6                     6                  3      

Bug 2: If we remove the root of the tree, should assign the new child node to the root.
For exmaple, given a tree (A), if we remove node 6, it should looks like (B), but now it looks like (C).

      (A)                   (B)                (C)
Root ->  6             Root -> 8         Root -> 6
          \                   / \
           8                 7   9                8
          / \                                    / \
         7   9                                  7   9

@aalhour
Copy link
Owner

aalhour commented Jan 14, 2018

Nice catch, thanks for contributing!

@aalhour aalhour merged commit a92846c into aalhour:master Jan 14, 2018
MetSystem pushed a commit to MetSystem/C-Sharp-Algorithms that referenced this pull request Sep 6, 2018
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