Question

Consider the AVL Tree built by inserting the following sequence of integers, one at a time: 5, 2, 8, 7,9 Then we insert 11. AIts 1AM, and all through the house, not a creature was stirring... except for your TA. Theyve been given the Pre-Order trav

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

1.

Step 1 :

The first element to be inserted is 5.

5

Step 2 :

The next element to be inserted is 2.

5 2

Step 3 :

The next element to be inserted is 8.

5 2 8

Step 3 :

The next element to be inserted is 7.

5 2 8 7

Step 4 :

The next element to be inserted is 9.

5 8 2 7 9

Step 4 :

The next element to be inserted is 11.

5 8 2 7 9 11

This would cause the tree to be unbalanced because node 5 will have a balance factor of -2.

Thus, the correct answer is option b.

2.

The given preorder traversal is V P G U X Y

In a binary search tree, the inorder traversal is always in sorted order.

So, the inorder traversal is G P U V X Y

The first element of preorder traversal is always the root of the tree.

V is the root of the tree.

V

So, the left and right subtree of V is divided as :

Left Root Right
G P U V X Y

The next element in preorder traversal is P and it is in the left subtree of root V.

The tree becomes :

V Р

The next element in preorder traversal is G and G is to the left of P in inorder traversal.

The tree becomes :

V Р G

The next element in preorder traversal is U and U is to the right of P in the inorder traversal.

V Р с G

The next element in preorder traversal is X and it is to the right of root element V..

The tree becomes :

V Х P G U

The next element in preorder traversal is Y and it is to the right of X in inorder traversal.

The tree becomes :

V X Р Y G U

So, the final tree is :

V X Р Y G U

The following steps are used to find the postorder traversal.

  • Start from the root and traverse towards the left until a node with no right child occurs.
  • The node selected is G. So, G is the first node in the postorder traversal.
  • Backtrack from node G to its parent P. Move to the right child U which is already a leaf.
  • The next node in the postorder traversal is U.
  • Backtrack from node U to its parent P. Since all the descendents of P have been visited, the next node in the postorder traversal is P.
  • Backtrack from P to its parent V. Move to its right child X and traverse the subtree until a node with no right child is found.
  • The node selected is Y.  The next node in the postorder traversal is Y.
  • Backtrack from node Y to its parent X. Since all the descendents of X have been visited, the next node in the postorder traversal is X.
  • Backtrack from X to its parent V. Since all the descendents of V have been visited, the next node in the postorder traversal is V.

Thus, the postorder traversal is :

G U P Y X V

For the level order traversal,

Level 1 visits the node V from left to right.

Level 2 visits the nodes P and X from left to right.

Level 3 visits the nodes G, U and Y from left to right.

Thus, the level order traversal is :

V P X G U Y.

Add a comment
Know the answer?
Add Answer to:
Consider the AVL Tree built by inserting the following sequence of integers, one at a time:...
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
  • Q8 - Construct a Binary Search Tree by inserting the following sequence of numbers. 5,6,3,2,10,4,1,7,9,8. Write...

    Q8 - Construct a Binary Search Tree by inserting the following sequence of numbers. 5,6,3,2,10,4,1,7,9,8. Write down the level ordered traversal sequence of the final tree after insert. Delete node 10, 8, and 6 step by step using in-order successor. Write down the level ordered traversal sequence after every delete. I want you to write down (1 level ordered traversal for the insert and 3 level-ordered traversals for the deletes). In total there should be 4 level-ordered traversal sequences in...

  • There are N numbers in the sequence. Please insert those numbers into an empty AVL tree...

    There are N numbers in the sequence. Please insert those numbers into an empty AVL tree one by one. After the AVL tree has been constructed: (1) Input: N The sequence of numbers Number which will be deleted from the tree (2) Print out The sequence of the tree by pre-order traversal The sequence of the tree by in-order traversal The sequence of the tree by post-order traversal NEW TREE AFTER DELETING number The sequence of the tree by pre-order...

  • Suppose we insert the numbers 4,5,6,7, and 8 into and AVL tree in that order. Then...

    Suppose we insert the numbers 4,5,6,7, and 8 into and AVL tree in that order. Then we traverse the tree via a post-order traversal and print the number at each node. In which order would the numbers print?

  • Draw an AVL tree (initially empty) at each step when inserting the following numbers in order:...

    Draw an AVL tree (initially empty) at each step when inserting the following numbers in order: 1; 2; 5; 4; 6; 3; 10; 9; 7; 8 Now, draw the above AVL tree at each step when deleting the following numbers in order (assuming that the substitution on deleting a node is done by replacing it with the minimum in the right subtree): 4; 5; 6

  • QUESTION 1 In a tree, a ____ is a node with successor nodes. root child descendent...

    QUESTION 1 In a tree, a ____ is a node with successor nodes. root child descendent parent sibling QUESTION 2 In a tree, the ____ is a measure of the distance from a node to the root. count degree branch height level QUESTION 3 Which of the following is not a characteristic of a binary search tree? Each node has zero, one, or two successors. The preorder traversal processes the node first, then the left subtree, and then the right...

  • True or false? (a) An insertion in an AVL tree with n nodes requires Θ (log(n))...

    True or false? (a) An insertion in an AVL tree with n nodes requires Θ (log(n)) rotations. (b) A set of numbers are inserted into an empty BST in sorted order and inserted into an empty AVL tree in random order. Listing all elements in sorted order from the BST is O (n), while listing them in sorted order from the AVL tree is O (log(n)). (c) If items are inserted into an empty BST in sorted order, then the...

  • 4. Consider the following subtree of a balanced AVL tree a b AA d X Y d+1 d+2 Now, suppose that subtrees (i.e., subtree...

    4. Consider the following subtree of a balanced AVL tree a b AA d X Y d+1 d+2 Now, suppose that subtrees (i.e., subtree X and subtree Y) to be both two levels deeper than its right subtree (i.e., subtree Z) so that we have the following unbalanced AVL tree node at the bottom of subtree Z is deleted, causing its two left a a b d d+1 X d+2 Describe how the AVL tree can be rebalanced. Draw the...

  • I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if...

    I need question 9-10 answered. Thank you Question 1 iShow the resulting binary search tree if we are to insert following elements into the tree in given order, [34, 12, 23, 27,31,9,11,45, 20, 37. i) Show the resulting balanced binary search tree if we are to insert following sorted elements into the tree, [9,12,21, 23, 29, 31, 34, 45, 48, 52, 55] iii What is the pre-order traversal of the balanced binary search tree? v) What is the post-order traversal...

  • PROBLEM 6: Suppose we insert keys below into an initially empty binary search tree in the...

    PROBLEM 6: Suppose we insert keys below into an initially empty binary search tree in the given order 6, 9, 2, 1, 5, 7, 10, 8, 3,4 (a) Draw the resulting binary search tree. (b) List the keys according to: A pre-order traversal An in-order traversal A post-order traversal (c) Now we perform some deletions using the "deletion by copying" strategy in which promoted keys are always drawn from a node's right subtree (so that there is only one correct...

  • PROBLEM 6: Suppose we insert keys below into an initially empty Vanilla binary search tree in...

    PROBLEM 6: Suppose we insert keys below into an initially empty Vanilla binary search tree in the given order: 6, 9, 2, 1, 5, 7, 10, 8, 3, 4 (a) Draw the resulting binary search tree. (b) List the keys according to: A pre-order traversal An in-order traversal A post-order traversal (c) Now we perform some deletions using the “deletion by copying” strategy in which promoted keys are always drawn from a node’s right subtree (so that there is only...

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