Question

Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elements. In this problem, you w
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer A->

In tree there are at most n nodes. It is right chained so it is having 1 leaf node and n-1 parent nodes.

So to get right chained binary tree from binary tree.Take right most element as leaf node

and then for every parent if it has left child make parent as right child of its left child by right rotation.In case if left child is already having right child then there is left rotation is done I am giving you example to solve this problem

So, there can be at most rotation for each parent node

Ca (L) 2 2

So each time parent will become right child of its left child in right rotation.

parent will become left child of its right child in left rotation.So there are at max 1 rotation is required to make a parent to child.

Answer 2->If you are having right chained binary tree.You need p rotation to make x as root where p is total number ancestors of x.To make root we will need to perform p left rotation .example is shown in below picture

anator 3

Answer c-> To transform Tree T1 to T2 we need left and right rotation accordingly. We need to reverse back all operations of b and a to get back the tree

Algorithm ->

as we know the depth can be more so , we need to first go till leaf node so that roatation can be performed

function (btree):

               if btree->leftchild

                       function(btree->leftchild);

                       roatate_right(btree)

              else if btree->leftchild=NULL and btree->rightchild

                      rotate_left(btree)

rotate_left ( btree ):

             btree->leftchild=btree->leftchild->rightchild

             btree->leftchild->rightchild=btree;

rotate_right ( btree ):

             btree->rightchild=btree->rightchild->leftchild

             btree->rightchild->leftchild=btree;

These rotation are same as AVL tree.

If you have any doubt.Please feel free to ask.Thanks          

Add a comment
Know the answer?
Add Answer to:
Problem 2 [35 points (155 15)]: Let Ti and T2 be two binary search trees containing the same elem...
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
Active Questions
ADVERTISEMENT