Skip to content

fix bug: edge case of avl delete #4001

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

Closed
wants to merge 3 commits into from

Conversation

Leo-LiHao
Copy link
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Dec 3, 2020
@ghost
Copy link

ghost commented Dec 3, 2020

Pull Request Report

@Leo-LiHao Hello! I'm a bot made to check all the pull request Python files. First of all, I want to say thank you for your time and interest in this project and for opening a pull request. There seems to be missing requirements in some of the Python files submitted in this pull request. Please read through the report and make the necessary changes. You can take a look at the relevant links provided after the report.

What are node paths? 🔽

The report contains headings and a checklist where the items are paths to the class/function/parameter where the requirement is missing. Node paths are double colon :: separated names and can be in any of the following format:

  • Class path: [file_name]::[class_name]
  • Function path: [file_name]::[function_name]
  • Function parameter path: [file_name]::[function_name]::[parameter_name]
  • Method path: [file_name]::[class_name]::[function_name]
  • Method parameter path: [file_name]::[class_name]::[function_name]::[parameter_name]

Following functions require tests [doctest/unittest/pytest]:

  • data_structures/binary_tree/avl_tree.py::my_queue::is_empty
  • data_structures/binary_tree/avl_tree.py::my_queue::push
  • data_structures/binary_tree/avl_tree.py::my_queue::pop
  • data_structures/binary_tree/avl_tree.py::my_queue::count
  • data_structures/binary_tree/avl_tree.py::my_queue::print
  • data_structures/binary_tree/avl_tree.py::my_node::get_data
  • data_structures/binary_tree/avl_tree.py::my_node::get_left
  • data_structures/binary_tree/avl_tree.py::my_node::get_right
  • data_structures/binary_tree/avl_tree.py::my_node::get_height
  • data_structures/binary_tree/avl_tree.py::my_node::set_data
  • data_structures/binary_tree/avl_tree.py::my_node::set_left
  • data_structures/binary_tree/avl_tree.py::my_node::set_right
  • data_structures/binary_tree/avl_tree.py::my_node::set_height
  • data_structures/binary_tree/avl_tree.py::get_height
  • data_structures/binary_tree/avl_tree.py::my_max
  • data_structures/binary_tree/avl_tree.py::right_rotation
  • data_structures/binary_tree/avl_tree.py::left_rotation
  • data_structures/binary_tree/avl_tree.py::lr_rotation
  • data_structures/binary_tree/avl_tree.py::rl_rotation
  • data_structures/binary_tree/avl_tree.py::insert_node
  • data_structures/binary_tree/avl_tree.py::get_rightMost
  • data_structures/binary_tree/avl_tree.py::get_leftMost
  • data_structures/binary_tree/avl_tree.py::del_node
  • data_structures/binary_tree/avl_tree.py::AVLtree::get_height
  • data_structures/binary_tree/avl_tree.py::AVLtree::insert
  • data_structures/binary_tree/avl_tree.py::AVLtree::del_node
  • data_structures/binary_tree/avl_tree.py::AVLtree::__str__
  • data_structures/binary_tree/avl_tree.py::_test

Following class/functions/parameters require descriptive names:

  • data_structures/binary_tree/avl_tree.py::my_max::a
  • data_structures/binary_tree/avl_tree.py::my_max::b

Following functions require return type hints:

NOTE: If the function returns None then provide the type hint as def function() -> None

  • data_structures/binary_tree/avl_tree.py::my_queue::__init__
  • data_structures/binary_tree/avl_tree.py::my_queue::is_empty
  • data_structures/binary_tree/avl_tree.py::my_queue::push
  • data_structures/binary_tree/avl_tree.py::my_queue::pop
  • data_structures/binary_tree/avl_tree.py::my_queue::count
  • data_structures/binary_tree/avl_tree.py::my_queue::print
  • data_structures/binary_tree/avl_tree.py::my_node::__init__
  • data_structures/binary_tree/avl_tree.py::my_node::get_data
  • data_structures/binary_tree/avl_tree.py::my_node::get_left
  • data_structures/binary_tree/avl_tree.py::my_node::get_right
  • data_structures/binary_tree/avl_tree.py::my_node::get_height
  • data_structures/binary_tree/avl_tree.py::my_node::set_data
  • data_structures/binary_tree/avl_tree.py::my_node::set_left
  • data_structures/binary_tree/avl_tree.py::my_node::set_right
  • data_structures/binary_tree/avl_tree.py::my_node::set_height
  • data_structures/binary_tree/avl_tree.py::get_height
  • data_structures/binary_tree/avl_tree.py::my_max
  • data_structures/binary_tree/avl_tree.py::right_rotation
  • data_structures/binary_tree/avl_tree.py::left_rotation
  • data_structures/binary_tree/avl_tree.py::lr_rotation
  • data_structures/binary_tree/avl_tree.py::rl_rotation
  • data_structures/binary_tree/avl_tree.py::insert_node
  • data_structures/binary_tree/avl_tree.py::get_rightMost
  • data_structures/binary_tree/avl_tree.py::get_leftMost
  • data_structures/binary_tree/avl_tree.py::del_node
  • data_structures/binary_tree/avl_tree.py::AVLtree::__init__
  • data_structures/binary_tree/avl_tree.py::AVLtree::get_height
  • data_structures/binary_tree/avl_tree.py::AVLtree::insert
  • data_structures/binary_tree/avl_tree.py::AVLtree::del_node
  • data_structures/binary_tree/avl_tree.py::AVLtree::__str__
  • data_structures/binary_tree/avl_tree.py::_test

Following function parameters require type hints:

  • data_structures/binary_tree/avl_tree.py::my_queue::push::data
  • data_structures/binary_tree/avl_tree.py::my_node::__init__::data
  • data_structures/binary_tree/avl_tree.py::my_node::set_data::data
  • data_structures/binary_tree/avl_tree.py::my_node::set_left::node
  • data_structures/binary_tree/avl_tree.py::my_node::set_right::node
  • data_structures/binary_tree/avl_tree.py::my_node::set_height::height
  • data_structures/binary_tree/avl_tree.py::get_height::node
  • data_structures/binary_tree/avl_tree.py::my_max::a
  • data_structures/binary_tree/avl_tree.py::my_max::b
  • data_structures/binary_tree/avl_tree.py::right_rotation::node
  • data_structures/binary_tree/avl_tree.py::left_rotation::node
  • data_structures/binary_tree/avl_tree.py::lr_rotation::node
  • data_structures/binary_tree/avl_tree.py::rl_rotation::node
  • data_structures/binary_tree/avl_tree.py::insert_node::node
  • data_structures/binary_tree/avl_tree.py::insert_node::data
  • data_structures/binary_tree/avl_tree.py::get_rightMost::root
  • data_structures/binary_tree/avl_tree.py::get_leftMost::root
  • data_structures/binary_tree/avl_tree.py::del_node::root
  • data_structures/binary_tree/avl_tree.py::del_node::data
  • data_structures/binary_tree/avl_tree.py::AVLtree::insert::data
  • data_structures/binary_tree/avl_tree.py::AVLtree::del_node::data
Relevant links 🔽

@ghost ghost added require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html and removed awaiting reviews This PR is ready to be reviewed labels Dec 3, 2020
@amaank404
Copy link
Contributor

Possibly could you make the changes that bot said while also fixing the bug?

@dhruvmanila
Copy link
Member

@algorithms-keeper review

@ghost ghost added the enhancement This PR modified some existing files label Dec 10, 2020
@dhruvmanila dhruvmanila removed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Dec 10, 2020
@ghost ghost added awaiting reviews This PR is ready to be reviewed labels Dec 10, 2020
@dhruvmanila
Copy link
Member

@Leo-LiHao Hey can you describe as to what the bug is?

@ghost ghost mentioned this pull request Dec 10, 2020
14 tasks
@Leo-LiHao
Copy link
Contributor Author

@Leo-LiHao Hey can you describe as to what the bug is?

Yes, I will add a test case later. Could you check my another PR? #4028 (comment)

@Leo-LiHao
Copy link
Contributor Author

@dhruvmanila I added two test cases (one with 15 values, one with 1000 values), and here's the output of original code for 15 values after deleting 7 values (8 values left in the tree now):

        12        
    2        13    
  0    5    *    14  
 *  1  *  6  *  *  *  * 

after deleting value 13

        5        
    2        12    
  0    *    6    14  
 *  1  *  *  *  *  *  * 
*************************************

It is not an AVL tree (look at the subtree of 2).

You could check the modified code and new test cases for more details.

@stale
Copy link

stale bot commented Jan 10, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Jan 10, 2021
@stale
Copy link

stale bot commented Jan 17, 2021

Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

@stale stale bot closed this Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files question stale Used to mark an issue or pull request stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants