Question

Build an AVL tree for the following collection of numbers in the given order. Show the balance factor for each node. 20, 40,

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Insertion an element into AVL tree is similar to that of BST. The balance factor (= height of left subtree - height of right subtree of the node) are calculated and if any of the nodes have a balance factor greater than 1, we need to perform rotation to restore the AVL tree.
  • To perform rotation, it is necessary to identify a specific node A, whose Balance factor (BF) is neither -1 , 0 or 1 and which is nearest ancestor to the inserted node on the path from the inserted node to the root of the tree.
  • There are 4 types of rotation:
    • LL - Inserted node is in the left subtree of the left subtree of the root
    • RR - Inserted node is in the right subtree of the right subtree of the root
    • LR - Inserted node is in the right subtree of the left subtree of the root
    • RL - Inserted node is in the left subtree of the right subtree of the root
  • LL and RR rotations are called single rotation whereas RL and LR are known as double rotations. LR comprises of RR followed by LL and RL comprises of LL followed by RR.

AVL tree after inserting : 20, 40, 80, 60, 55, 11, 99, 77 , 33:

Step 1: Insert 20 Since AVL Tree in empty, make 20 as the root Tree (20) Step 2: Insert 40 Since 40720, it is inserted subtre

since balance factor (BF) of 20 =-2 because so has been insested cuchich is in the right subtree of right subtree of 200, t b

Since Br of so = 2 because 55 has been inserted (which is in the left subtree of left subtree of sol. So to balance we will d

Step 8: Insert 77 + Step 9: Insest 33 Final AVL free! 10300

Add a comment
Know the answer?
Add Answer to:
Build an AVL tree for the following collection of numbers in the given order. Show the...
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