Hi,
I am trying to create a method to check if a binary tree is an AVL tree without using the height method of the author's binary tree. This is my code USING the height:
public boolean isAVL(BinaryNode<AnyType> t)
{
int leftSubtreeHeight;
int rightSubtreeHeight;
if (t == null)
return true;
if (t.right != null && t.left != null) {
leftSubtreeHeight = height(t.left);
rightSubtreeHeight = height(t.right);
if (Math.abs(leftSubtreeHeight - rightSubtreeHeight) > 1 || Math.abs(rightSubtreeHeight - leftSubtreeHeight) > 1)
return false;
}
return true && isAVL(t.left) && isAVL(t.right);
}
This code works, but I need to find a way to find out if the tree is AVL balanced WITHOUT using the height method. I am boggled since the AVL definition is a tree that has subtrees that have a height difference of 0 or 1. Therefore, I cannot figure out how to create an AVL method without knowing the heights of the subtrees.
Thanks for any help!