Question

In: Computer Science

Insert the list of elements [11, 14, 16, 4, 7, 2, 23, 28, 19] in this...

Insert the list of elements [11, 14, 16, 4, 7, 2, 23, 28, 19] in this order, into an initially empty AVL tree.     Show the details of the insertion process.       Note:    You must draw a different tree to show the result of each rotation involved. If an insertion requires a double rotation, you must show the result of each rotation separately.

Solutions

Expert Solution

The list of elements is given as [11, 14, 16, 4, 7, 2, 23, 28, 19] .

The balance factor of a node is the difference between the height of its left subtree and the height of its right subtree and in an AVL tree, the balance factor of a node must be either -1, 0 or 1.

The insertion process into an AVL tree takes place as follows :

Step 1 :

The first element to be inserted is 11.

The AVL tree becomes :

Step 2 :

The next element to be inserted is 14. Since 14 is greater than 11, it is placed as the right child of 11.

The AVL tree becomes :

Step 3 :

The next element to be inserted is 16. Since 16 is greater than 14, it is placed as the right child of 16.

The AVL tree becomes :

But here the balance factor of node with key 11 is violated as it is 0 - 2 = -2.

Perform single left rotation with respect to node with key 11.

The AVL tree becomes :

Step 4 :

The next element to be inserted is 4. Since, 4 is less than 11, it is placed as the left child of 11.

The AVL tree becomes :

Step 5 :

The next element to be inserted is 7. Since, 7 is greater than 4 and less than 11, it is added as the right child of 4.

The AVL tree becomes :

But here the balance factor of node with key 11 is violated 2 - 0 = 2.

Perform double right rotation on the nodes with key 4 and key 11.

So, at first, left rotation is performed with respect to node 4.

The AVL tree becomes :

Then, right rotation is performed.

The AVL tree becomes :

Step 6 :

The next element to be inserted is 2. Since, 2 is less than 4, it is added as the left child of 4.

The AVL tree becomes :

But here the balance factor of node with key 14 is violated as 3 - 1 = 2.

Perform single right rotation with respect to node with key 14 that is the root node.

The AVL tree becomes :

Step 7 :

The next element to be inserted is 23. Since, 23 is greater than 16, it is added as the right child of node with key 16.

The AVL tree becomes :

Step 8 :

The next element to be inserted is 28. Since, 28 is greater than 23, it is added as the right child of 23.

The AVL tree becomes :

But here the balance factor of node with key 16 is violated as 0 - 2 = -2.

Perform single left rotation with respect to node with key 16.

The AVL tree becomes :

Step 9 :

The next element to be inserted is 19. Since, 19 is greater than 16 and less than 23, it is added as the right child of 16.

The AVL tree becomes :

But here the balance factor of node with key 14 is violated as 1 - 3 = -2.

Perform double left rotation with respect to node with key 14.

So, at first perform the right rotation in double rotation technique and the AVL tree becomes :

Now perform left rotation with respect to node with key 16.

The AVL tree becomes :

The final AVL tree after the insertion of the given elements is :


Related Solutions

Buffalo Boston 26 23 27 14 39 11 23 19 17 19 16 4 21 9...
Buffalo Boston 26 23 27 14 39 11 23 19 17 19 16 4 21 9 31 12 1 12 23 7 32 32 32 26 24 21 42 16 38 16 29 18 16 16 12 20 29 20 16 11 18 10 27 18 2 11 21 17 35 20 21 20 29 25 24 16 17 17 21 8 38 21 9 24 31 26 16 27 24 18 24 17 13 15 21 21 21 32...
Low Medium High 14 18 16 6 17 20 11 23 18 12 17 16 11...
Low Medium High 14 18 16 6 17 20 11 23 18 12 17 16 11 10 15 9 20 16 6 15 16 12 17 17 14 25 11 11 11 13 4 18 22 9 18 16 7 20 10 12 21 18 12 27 9 17 13 19 11 22 16 8 17 12 Our worksheets lists the number of 3+ syllable words in each magazine grouped by education level. Use your spreadsheet program to conduct a...
Post Position 1 2 3 4 5 6 7 8 9 10 Wins 19 14 11...
Post Position 1 2 3 4 5 6 7 8 9 10 Wins 19 14 11 15 15 7 8 12 5 11 The table below lists the frequency of wins for different post positions in the Kentucky Derby horse race. Use a 0.05 significance level to test the claim that the likelihood of winning is the same for the different post positions. What is the critical value (the X2 value)? [Round to the nearest thousandths place]
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Cork price 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Consider the following data set: {4, 7, 11, 12, 18, 19, 20, 22, 23, 25} Answer...
Consider the following data set: {4, 7, 11, 12, 18, 19, 20, 22, 23, 25} Answer the following questions. If necessary, round your answers to four decimal places. (a) Find the sample median of the data set. (b) How much can you increase the smallest value from the data set without getting the value of the sample median changed? (Enter NA if there is no limit to the amount.) (c) How much can you decrease the largest value from the...
MT scores: 11, 11, 16, 17, 19, 20, 21, 21 23 24 24 26 26 27...
MT scores: 11, 11, 16, 17, 19, 20, 21, 21 23 24 24 26 26 27 27 28 28 28 29 30 31 31 32 33 35 37 38 38 39 42 44 Questions for Class MT Score Distribution Analysis 1. Create a boxplot of MT scores. 2. Compute the probability that a randomly selected student from the class scored higher than 20. 3. Are the MT scores normally distributed? Why or why not? 4. Assuming a normal fit, compute...
MT scores: 11, 11, 16, 17, 19, 20, 21, 21 23 24 24 26 26 27...
MT scores: 11, 11, 16, 17, 19, 20, 21, 21 23 24 24 26 26 27 27 28 28 28 29 30 31 31 32 33 35 37 38 38 39 42 44 Questions for Class MT Score Distribution Analysis 1. Create a histogram of MT scores. 2. Describe the shape of the MT scores distribution. 3. Compute the mean and standard deviation. 4. Compute the 5-number summary. 5. Create a boxplot of MT scores. 6. Compute the probability that...
4. Insert 21, 9, 28, 4, 15, 26, 30, 10, 2, 37, 17, 88 into the...
4. Insert 21, 9, 28, 4, 15, 26, 30, 10, 2, 37, 17, 88 into the AVL Tree. Have the balancing factor. Don't write a program. Just please manually solve the problem. Thanks.
Below is a dataset. xi 1 2 3 4 5 yi 3 7 5 11 14...
Below is a dataset. xi 1 2 3 4 5 yi 3 7 5 11 14 Use the facts that ˆy = .20 + 2.6x, ̄x = 3, ̄y= 8, Σ(xi − ̄x)^2 = 10, and SSE=12.4. a. Estimate the standard deviation of ˆy∗ when x= 4. b. Develop a 95% confidence interval for the expected value of y when x= 4. c. Estimate the standard deviation of an individual value of y when x= 4. d. Develop a 95%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT