Wrong answer in AVL-Tree exercise
HardMax71 opened this issue · comments
Describe the bug
The type of rotation after specific action in solutions.pdf is false, although the tree is correct.
To Reproduce
0. Seed = 4.
- Go to "AVL-Trees", part with delete(17).
- Execute all inserts/deletes before delete(17).
- Execute delete(17).
- Open solutions.pdf, there will be "l-r rotation" instead of "no rotation".
Expected behavior
"No rotation" is expected.
Solution (after delete(17)) in solutions.pdf :
Solution path (used https://www.cs.usfca.edu/~galles/visualization/AVLtree.html) :
https://gyazo.com/e05859c74b19c312d042c142966c4fb8
Desktop (please complete the following information):
- IDE IntelliJ
- Java 11
Additional context
Add any other context about the problem here.
The algorithm seems to switch 17 with 24 instead of the correct 12. Because of that, the balance difference is 2/-1. After the l/r rotation is carried out, the tree is correct again.
Technically, there was nothing wrong and it was a simple issue of which node to replace the deleted node with if it has two children. Since GAD standardizes it to be the predecessor, our implementation is wrong and this will be fixed after some more testing.
This would also mean that the arrival at that position was incorrect since delete(16) should have resulted in 16 being replaced by 12 (predecessor). This is also the way it works in the simulator by David Galles (USFCA).
Side note: It's 2:30 am and I have no idea why I just did this for 30 minutes instead of going to sleep