Question

Suppose you are given a balanced binary search tree with 15 nodes in it, containing the even numb...

  1. Suppose you are given a balanced binary search tree with 15 nodes in it, containing the even numbers from 2 to 30 inclusive.

    1. (a) (5 points) Draw this tree.

    2. (b) (3 points) Explain how you would check if the number 18 is in this

      tree, and state the number of operations this would take.

    3. (c) (2 points) Explain how you would insert the number 27 into this tree,

      and state the number of operations this should take.

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

a). Tiee! 2g

b).1st operation :- 18 will be compared with root.if it is equal it return yes.but 18 is not equal to 16 so,2nd operation is performed.

2nd operation:- If 18 is not equal to root(which is the case here) then it checks whether 18 is greater or smaller than root.clearly,it is greater than 16 so,it moves to right child of root.

3rd operation:- it is same as 1st operation except for the fact that the root is now right child i.e 24.

4th operation:-Same as 2nd operation but here 18 is smaller than 24 so,it moves to the left child of current root i.e 24.

5th operation:-same as 1st operation except here root is 20.

6th operation:- same as 2nd operation but here 18 is smaller than 20,so,search proceeds on left child of 20.

7th operation:-same as 1st operation but here 18 is actually equal to 18 so it return yes.

c).To insert any data into Balanced BST follow this procedure:-

i).First find the correct place for the node in balanced BST.this step takes O(logn) time.

ii).now,attach the node to its correct place.

iii).Check if the tree is balanced or not?if it not then perform appropriate rotations.

24く14 28 217 28 20 omeet plare Lo7vie bolancivg fach other thon I, 0,) 2-6 0

Add a comment
Know the answer?
Add Answer to:
Suppose you are given a balanced binary search tree with 15 nodes in it, containing the even numb...
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
  • (20 points) Suppose you are given a binary search tree T of n nodes (as discussed...

    (20 points) Suppose you are given a binary search tree T of n nodes (as discussed in class. each node v has v.left, v.right, and v.key). We assume that no two keys in T are equal. Given a value x, the rank operation rank() is to return the rank of x in T, which is defined to be one plus the number of keys of T smaller than 2. For example, if T has 3 keys smaller than r, then...

  • Show that the tree height of a height-balanced binary search tree with n nodes is O(log...

    Show that the tree height of a height-balanced binary search tree with n nodes is O(log n). (Hint: Let T(h) denote the fewest number of nodes that a height-balanced binary search tree of height h can have. Express T(h) in terms of T(h-1) and T(h-2). Then, find a lower bound of T(h) in terms of T(h-2). Finally, express the lower bound of T(h) in terms of h.)

  • 1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9...

    1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9 5 15 10 17 8 Figure 1: Binary Tree: The letter next to each node (e.g., a, b) denotes the tree node, and the number inside each node is the key. 1.1 Correctness (10 points) Is this binary tree a valid binary search tree? In other words, does it satisfy the binary search tree property? If not, which node(s) violates the binary search tree...

  • In general, assuming a balanced BST with n nodes (A balanced binary tree has roughly the...

    In general, assuming a balanced BST with n nodes (A balanced binary tree has roughly the same number of nodes in the left and right subtrees of the root), what is the maximum number of operations required to search for a key? Please notice that the tree in this exercise is not balanced. Trace the algorithm for creating a parse tree for the expression (((4 x 8)/6)–3 Please help me understand :(

  • Suppose a binary search tree has multiple nodes containing the same key value, k. Let node...

    Suppose a binary search tree has multiple nodes containing the same key value, k. Let node p be the lowest common ancestor of such nodes. Then, the key of p must be also k. If this is true, provide an argument. Otherwise, provide a counterexample.

  • IN JAVA create a binary search tree gui where you can insert and remove nodes, also...

    IN JAVA create a binary search tree gui where you can insert and remove nodes, also move around the tree, thank you. The simpler the better.

  • 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...

  • Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of...

    Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of height h is 2h+1 − 1. 2. A full node is a node with two children. Prove that the number of full nodes plus one is equal to the number of leaves in a nonempty binary tree. 3. What is the minimum number of nodes in an AVL tree of height 15? 4. Show the result of inserting 14, 12, 18, 20, 27, 16,...

  • In regards to binary search tree, can you answer why a BST with N nodes has...

    In regards to binary search tree, can you answer why a BST with N nodes has at least log2N levels and at most N levels. so the runtime complexity is best case 0(logN) and worst case 0(N). Can you explain this with the following numbers in this order? 7,1,64,28,77

  • in python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree...

    in python 11.1 Binary Search Tree In this assignment, you will implement a Binary Search Tree You will also need to implement a Node class. This class will not be tested, but is needed to implement the BST. Your BST must implement the following methods. You are free to implement additional helper methods. It is recommended you create your own helper methods Constructor: Creates an Empty Tree String Method: Returns the string "Empty Tree" for an empty tree. Otherwise, returns...

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