Question

2. a) Consider the following AVL Tree. 50 / 25 75 10 Insert the following values in the given AVL Tree, one after another, an

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

AVL Tree:Balancing Factor(BF) = Height of Left Subtree - Height of Right Subtree
This Balancing Factor(BF) is either 0,1,-1 then AVL Tree is balanced

Step 1: Insert keys 17

50 BF = 2 25 75 BF = 2 BF = 0 10 BF = -1 17 BF = 0

After Insertion the tree is Not balanced so Perform Double Rotate Right

50 BF = 1 17 75 BF = 0 BF = 0 10 25 BF = 0 BF = 0

Step 2: Insert key 40                           

50 BF = -2 17 BF = -1 75 BF = 0 10 25) BF = -1 BF = 0 40 BF = 0

Step 3: Insert key 10

50 BF = -2 17 BF = -1 75 BF = 0 10 25 BF = -1 BF = 0 40 BF = 0

After Insertion the tree is Not balanced so Perform Double Rotate Right

25 BF = 0 17 BF = 1 50 BF = 0 10 40 75 BF = 0 BF = 0 BF = 0

Step 4: Insert key 90                                                                

25 BF = -1 17 BF = 1 50 BF =-1 10 40 75 BF = -1 BF = 0 BF = 0 90 BF = 0

Step 5: Insert key 5  

25 BF = 0 17 50 BF = -1 BF = 2 10 BF = 1 40 BF = 0 BF = -1 75 5 BF = 0 BF = 0 (90

After Insertion the tree is Not balanced so Perform Single Rotate Right

25 BF = -1 BF = 0 10 50 BF = -1 5 17 40 75 BF = -1 BF = 0 BF = 0 BF = 0 BF = 0 (90

Step 6: Insert key 100

25 BF = -2 10 BF = 0 50 BF = -2 5 17 40 75 BF = -2 BF = 0 BF = 0 BF = 0 90 BF = -1 100 BF = 0

After Insertion the tree is Not balanced so Perform Single Rotate Left

25 BF = -1 BF = 0 ( 10 50 BF =-1 5 17 40 90 BF = 0 BF = 0 BF = 0 BF = 0 75 100 BF = 0 BF = 0

Which is Required AVL Tree after performing all Insertions

b) Given Tree from Part (a)

25 BF = -1 BF = 0 ( 10 50 BF =-1 5 17 40 90 BF = 0 BF = 0 BF = 0 BF = 0 75 100 BF = 0 BF = 0

Delete Root: Delete 25

Node to delete has two childrens so find largest element in the left subtree

25 BF = -1 BF = 0 (10 50 BF =-1 5 17 40 90 BF = 0 BF = 0 BF = 0 BF = 0 75 100 BF = 0 BF = 0

Copy largest value of the left subtree into Node to Delete

17 BF = -1 BF = 0 (10 50 BF =-1 5 17 40 90 BF = 0 BF = 0 BF = 0 BF = 0 75 100 BF = 0 BF = 0

17 BF = -1 BF = 1(10 50 BF =-1 5 40 90 BF = 0 BF = 0 BF = 0 75 100 BF = 0 BF = 0

Which is Required Red/Black Tree after performing Deletion of Root

Add a comment
Know the answer?
Add Answer to:
2. a) Consider the following AVL Tree. 50 / 25 75 10 Insert the following values...
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