Question

java AVL tree a). What are the conditions that must exist in a binary tree for calling the left and the right rotation? b). What is the smallest height that a tree of 1000 nodes can be? What is the bi...

java AVL tree

a). What are the conditions that must exist in a binary tree for calling the left and the right rotation?

b). What is the smallest height that a tree of 1000 nodes can be? What is the biggest?

Please be very specific, thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a)

The “balance factor” of a node in the AVL Tree determines whether or not it gets rotated. Keep track of the balance factor for each node in the tree and you'll be able to determine when you need to rotate easily.

The balance factor of a node “V” is calculated by subtracting the height of the right subtree of V from the height of the left subtree of V.

If the balance factor of any node is greater than 1 or less than -1, then a rotation needs to be performed. There are four rotation types: left, right, left-right, and right-left.

b)

  • If there are n nodes in AVL tree, minimum height of AVL tree is floor(log2n). Hence, the minimum height with 1000 nodes is: 9
  • If there are n nodes in AVL tree, maximum height can’t exceed 1.44*log2n. Hence, the maximum height is: 1.44 * log21000 = 14
Add a comment
Know the answer?
Add Answer to:
java AVL tree a). What are the conditions that must exist in a binary tree for calling the left and the right rotation? b). What is the smallest height that a tree of 1000 nodes can be? What is the bi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT