Hi ignl, I am learning the data struct lessons, and now about AVL tree. I'm glad to find your code here, it's helpful.
But I have a question about the AVLTree implementaion. It will not work properly in some situations I think, the problem code is below:
@Override
public Node insert(int element) {
Node newNode = super.insert(element);
rebalance((AVLNode)newNode);
return newNode;
}
The problem is, for an AVL tree, we need to reanlance the subtree from the parent of the inserted node, along with it's ancestor, until the root node, to guarantee the whole tree is balanced. But it's not done in your code, just one balancing here.
For example, if we insert serial numbers of 20 21 18 17 19, we got an AVL tree, now if we insert number 15, this tree will not be balanced.
What do you think about this, did I misunderstood your code?