AVL tree balance factors

In this book (p. 183, 3rd ed.) the balance factor is computed as leftHeight - rightHeight. But in the Wikipedia article the calculation is reversed, rightHeight - leftHeight. I’m wondering if this book’s approach is common, such that an interviewer would expect either approach and only care about consistency.

1 Like

@blwinters Thanks very much for your question!

The balance factor dictates which sort of rotation you need to use. If you choose the other way around, the rotations just need to rotate differently. Whether you choose one over the other isn’t important; Just make sure the rotations work based on whichever way you choose. :slight_smile:

I hope this helps!

All the best.