2 answers

Let T1 and T2 be AVL trees such that the largest key in T1 is less...

Question:

Let T1 and T2 be AVL trees such that the largest key in T1 is less than

the smallest key in T2. Give an algorithm (in psuedocode) for procedure JOIN-AVL-
TREES(T1, T2) that joins these two AVL trees. The runtime should be O(log n),

where n is the size of the resulting AVL tree. Can you explain how can we achieve this and why is the complexity such that?


Answers

We will begin by computing the heights ,H1 of T1 and H2 of T2. this will be taking time as O(H1+H2): we have to simply traverse the path begin from root , if balance factor is -1 than go towards left child , if balance factor is positive than go towards right child and if the balance factor is 0 than can go to any of the children until you reach leaf node.

Assume that H1>=H2 and the other cases are symmetric.

Next Step, DELETE the smallest element (let X) from T2 leaving T2' of Height H , this will take O(H2) time complexity.

find a node V on the rightmost path from the root of T1 , whose height is either H or H+1 , this can be illustrated as follows:

V<--root(T1)

H'<--H1

while H'>H+1 do

if balance factor (V) = -1

then H'<--H'-2

else

H'<--H'-1

V<--rightchild(V)

This will take O(H1) time.

Let U denotes the parent of V , from a new tree whose root contains the key X , whose left subtree is the subtree which is rooted at V and whose right subtree will be T2'.

NOTE: this is a valid binary search tree, since all the key of the subtree which are rooted at V in T1 and hence it is Smaller than X and by construction , X is smaller than or equal to all elements in T2'. The balance factor of the root of this new tree is H-H'. which will be valued to be either -1 or it will be 0. hence the new generated tree is a valid AVL TREE..

The height of this new tree is H'+1, which is one bigger than V's height.

Let the root of this new tree is the right child of U in place of V again, since all the keys in this new tree are at least as big as U, this will results in a valid binary search tree. this part of construction takes constant time.

Now when we will be in the INSERT Algorithm, we will go up to the tree, starting point will be U fixing balance factorand perhaps doing a rotation. this will take O(H1) time. NOTE that the correctness and efficiency will be follows from the condition which is at U before this process is begun is a condition that can arise during INSERT algorithm.

Since H1,H2 belongs to O(log n), hence the total time taken by this algorithm is in O(log n).

.

FTrst, compute the heig hts ot T, and T, Then, traverse siom te root, oing to let child om -he root , Qoing to left child the-Hen balance factor C)=-1 if 4. 5 else 8 7% algorithm takes O(h) fine. Let denote theborent e v Νοω , rm a neω-tree ωhose ro

The he ight new tree i-e., 1 bigger than new ree be the siht child let the aoor ain, becau se all keys n rew tree are at leat

.

Similar Solved Questions

1 answer
A simple pendulum is swinging back and forth through a small angle, its motion repeating every...
A simple pendulum is swinging back and forth through a small angle, its motion repeating every 1.34 s. How much longer should the pendulum be made in order to increase its period by 0.27 s?...
1 answer
Let X have a uniform distribution on the interval (0,1) a. Find the probability distribution of Y...
WILL THUMBS UP IF DONE NEATLY AND CORRECTLY! Let X have a uniform distribution on the interval (0,1) a. Find the probability distribution of Y-1 Enter a formula in the first box and a number in the second and third boxes corresponding to the range of y. Use * for multiplication, / for divison, for p...
1 answer
(Revision 9) (6 points) 5. A cereal company makes three kinds of cereal with wheat, com,...
(Revision 9) (6 points) 5. A cereal company makes three kinds of cereal with wheat, com, and oats. The proportions and profit of each cereal are shown in the table below. Set up the simplex tableau for this problem (do not solve the problem). W-O W-C-O W-C Wheat Corn Oats Profit/Kg 0.750 0.25 $0.30 ...
1 answer
Leslie Sporting Goods is a locally owned store that specializes in printing team jerseys. The majority...
Leslie Sporting Goods is a locally owned store that specializes in printing team jerseys. The majority of its business comes from orders for various local teams and organizations. While Leslie’s prints everything from bowling team jerseys to fraternity/sorority apparel to special event shirts,...
1 answer
Consider the mountain known as Mount Wolf, whose surface can be described by the parametrization (u,...
Consider the mountain known as Mount Wolf, whose surface can be described by the parametrization (u, v) = (u, v, 7565 - 0.0202 - 0.0312) with v2 + v2 = 10,000, where distance is measured in meters. The air pressure P(x, y, z) in the neighborhood of Mount Wolf is given by P(x, y, z) = 32el-7x2 + 4y2 ...
1 answer
9. In the figure, the charge in the middle is static equilibrium? 75 nC. For what...
9. In the figure, the charge in the middle is static equilibrium? 75 nC. For what charge q1 will charge q2 be in (l pointy ซีเ 0 92 10 cm 0 cm 15 nC 7.5 C 30 nC O 60 nC 10. Charge is given in microcoulombs. What must you multiply the charge by to use Coulomb's 1 point) law to c...
1 answer
Courteisha omework: Homework 2.1 core: 0 of 1 pt 2.4.47 11 of 14 (13 complete) ▼...
Courteisha omework: Homework 2.1 core: 0 of 1 pt 2.4.47 11 of 14 (13 complete) ▼ HW The ages (in years) and heights (n inches) of all pitchers for a baseball team are listed. Find the coefficient of variation for each of t results EE Click the icon to view the data sets. CVheights-3.6 % (Round...
1 answer
Refer to this picture. We have light entering from air into a second medium, which then...
Refer to this picture. We have light entering from air into a second medium, which then passes into a third, which then passes into a fourth. Find the index of refraction of the fourth medium provided theta1 is 35 deg, theta2 is 50 deg, theta3 is 40 deg, and theta 4 is 70 deg. AIR 03...
1 answer
The bent rod ABCDE rotates about a line joining Points A and E with a constant...
The bent rod ABCDE rotates about a line joining Points A and E with a constant angular velocity of 7.5 rad's. Knowing that the rotation is clockwise as viewed from E, determine the velocity and acceleration of corner C. (Round the final answer to two decimal places.) 200 min 250 mm B D 1:50 100 ...
1 answer
Question 8 According to a Pew Research Center study, in May 2011, 37% of all American...
Question 8 According to a Pew Research Center study, in May 2011, 37% of all American Type numbers in the boxes. adults had a smart phone (one which the user can use to read email and surf 10 points the Internet). A communications professor at a university believes this percentage is higher among co...
1 answer
The inventory turnover reflects how many times, on average, that the inventory balance was sold during...
The inventory turnover reflects how many times, on average, that the inventory balance was sold during the year. is increased when accounts receivable increases. is decreased if inventory balances decrease from the beginning of the year to the end of the year. is improved if cost of goods sold decre...
1 answer
Problem number 7 Simplify the following complex expressions into a single Phasor (ie, a single complex...
Problem number 7 Simplify the following complex expressions into a single Phasor (ie, a single complex number in polar notation in the form V = Ves iT Her Tz joan 1+ where R. Landare constants) Vio where and care constants) _ 1+ V2 je 1 preview Die 9 Th w...
1 answer
You are the science officer on a visit to a distant solar system
You are the science officer on a visit to a distant solar system. Prior to landing on a planet you measure its diameter to be 2.070E+7 m and its rotation to be 19.8 hours. You have previously determined that the planet orbits 1.590E+11 m from its star with a period of 368.0 Earth days. Once on the s...
1 answer
16. The table shows the points scored by a football team during each quarter of the...
16. The table shows the points scored by a football team during each quarter of the game. How many points did the team score during th entire game? Explain how you found your answer. 7EE.1, ZEE.2 First Quarter Second Quarter Third Quarter Fourth Quarter 3p 5p+2 1p p 4 m +1...
1 answer
D) An individual is heterozygous for the following reciprocally translocated chromosomes (* denotes the centromere): M-N-O-P-*-Q-R-S...
d) An individual is heterozygous for the following reciprocally translocated chromosomes (* denotes the centromere): M-N-O-P-*-Q-R-S V-w-x-*-y-z V-W-P-*-Q-R-S M-N-O-x-*-y-z Which non-recombinant haploid gametes below will result in a deficiency or duplication of genetic material in the fertilized em...
1 answer
X |。ACC 2223 Quizzes & Tests ilrn/takeAs ssignment/takeAssignmentMain.do?nwoker-ass Upgrade to macOS Mojave Get Dark Made, Stacks,...
x |。ACC 2223 Quizzes & Tests ilrn/takeAs ssignment/takeAssignmentMain.do?nwoker-ass Upgrade to macOS Mojave Get Dark Made, Stacks, new apPS and a new Mac App Store Not Now Details eBook Show Me How Print tem Entries for Cash Dividends The declaration, record, and payment dates in connecti...
1 answer
Why silica crucible is used instead sintered crucible in gravimetric analysis for barium as barium sulphate?
Why silica crucible is used instead sintered crucible in gravimetric analysis for barium as barium sulphate?...
1 answer
4. (20 points) Kellogg has 800 employees who receive 10 days of vacation per year to...
4. (20 points) Kellogg has 800 employees who receive 10 days of vacation per year to be taken any time. At December 31. 2017 Human Resources confirmed that there were a total of 8,500 days of vacation used in 2017; and there were a total of 5,500 days of vacation unused. Employee pay rates were as f...