Skip to content

[WIP] Added base class SelfBalancingTree for Red Black Tree #176

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

Merged
merged 4 commits into from
Mar 19, 2020

Conversation

HarsheetKakar
Copy link
Contributor

References to other Issues or PRs or Relevant literature

Please check if the made changes are advisable or should I just extend RedBlackTree from AVLTree.

Brief description of what is fixed or changed

Added SelfBalancingTree which consists rotations.

Other comments

@codecov
Copy link

codecov bot commented Mar 19, 2020

Codecov Report

Merging #176 into master will increase coverage by 0.016%.
The diff coverage is 93.103%.

@@              Coverage Diff              @@
##            master      #176       +/-   ##
=============================================
+ Coverage   96.735%   96.752%   +0.016%     
=============================================
  Files           23        23               
  Lines         1746      1755        +9     
=============================================
+ Hits          1689      1698        +9     
  Misses          57        57               
Impacted Files Coverage Δ
pydatastructs/trees/binary_trees.py 96.951% <93.103%> (+0.056%) ⬆️

Impacted file tree graph

@czgdp1807 czgdp1807 marked this pull request as ready for review March 19, 2020 13:38
@czgdp1807
Copy link
Member

Looks like a nice idea. Tests are also passing without modifications. The lines not covered in diff were not originally covered so not a concern of this PR. It looks like ready for merging.

@HarsheetKakar
Copy link
Contributor Author

ok so merge this one and I will try to implement RBTree by tomorrow.

@HarsheetKakar HarsheetKakar requested a review from czgdp1807 March 19, 2020 13:52
@czgdp1807
Copy link
Member

Are the rotation methods in _left_rotate generic enough? For example in #157 the rotations in SplayTree directly re-use the code in AVLTree . So, can we directly reuse the rotation methods in SelfBalancingBinaryTree in SplayTree. I observed that, AVLTree still have to do some stuff in their own rotation methods.

@HarsheetKakar
Copy link
Contributor Author

Are the rotation methods in _left_rotate generic enough? For example in #157 the rotations in SplayTree directly re-use the code in AVLTree . So, can we directly reuse the rotation methods in SelfBalancingBinaryTree in SplayTree. I observed that, AVLTree still have to do some stuff in their own rotation methods.

in AVLTree its just recalculating the height, which is necessary for balancing in AVL but in case of other trees eg. RedBlackTree we dont actually care about the absolute height. Rotations are not part of how a tree is built or what data its nodes hold, it just moves pointers that is why I dont think it will break the code.

@HarsheetKakar
Copy link
Contributor Author

Any way the code is actually cut from the original functions in AVL tree, so even if Splay Tree is extending from AVL tree there shouldn't be any problem.

@czgdp1807
Copy link
Member

Yes, but what if we subclass SelfBalancingBinaryTree in SplayTree? Will there be any affect on SplayTree in that case?

@HarsheetKakar
Copy link
Contributor Author

Yes, but what if we subclass SelfBalancingBinaryTree in SplayTree? Will there be any affect on SplayTree in that case?

IMO since they arnt doing anything with the height of tree then the code should be same, but I might have to look into SplayTree to be absolutely sure.

@HarsheetKakar
Copy link
Contributor Author

Just looked into it and I think it wont be a problem if we replace AVLTree with SelfBalancingBinaryTree since the rotations are still the same.

Reference:

https://www.youtube.com/watch?v=IBY4NtxmGg8

@czgdp1807
Copy link
Member

Currently the tests are not failing and if in future there is bug then we may need to restore the changes. Merging for now.

@czgdp1807 czgdp1807 merged commit f75c300 into codezonediitj:master Mar 19, 2020
@HarsheetKakar HarsheetKakar deleted the RBTree branch March 19, 2020 15:31
@HarsheetKakar
Copy link
Contributor Author

I am sorry, there is a major bug in SelfBalancingTree class, I am opening a PR to revert changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants