1.
Step 1 :
The first element to be inserted is 5.
Step 2 :
The next element to be inserted is 2.
Step 3 :
The next element to be inserted is 8.
Step 3 :
The next element to be inserted is 7.
Step 4 :
The next element to be inserted is 9.
Step 4 :
The next element to be inserted is 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.
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 :
The next element in preorder traversal is G and G is to the left of P in inorder traversal.
The tree becomes :
The next element in preorder traversal is U and U is to the right of P in the inorder traversal.
The next element in preorder traversal is X and it is to the right of root element V..
The tree becomes :
The next element in preorder traversal is Y and it is to the right of X in inorder traversal.
The tree becomes :
So, the final tree is :
The following steps are used to find the postorder traversal.
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.
Consider the AVL Tree built by inserting the following sequence of integers, one at a time:...
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 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 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: 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 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)) 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 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 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 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 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...