Question

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 property, and why? How would you modify the violating node(s) to make the binary tree a valid binary search tree? Hint: You will lose points if your answer includes tree nodes that do NOT violate the binary search tree property. Insertion (5 points) If we insert a node with key 18 into the binary search tree in Figure 1 (or the corrected version if you need to modify the tree node(s) in the first question), how would the binary search tree look like after the insertion? Please draw the binary search tree as in Figure 1.

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

Answers:

Ans 1.1.:

For a given Binary Tree to be a BInary Search Tree it has to follow all of the following properties:

1. All the keys in the left subtree of root are less than the key in the root.

2. All the keys in the right subtree of root are greater than the key in the root.

3 Left and right subtrees of root are also binary search Trees.

Now, In the given Binary Tree:
The root node a has value 9 and now all other nodes in the left subtree must have value less than 9 but node e has value 10 and thus it violates the 1st rule that we have seen according to which no node in the left subtree should have value greater than that of the root node. Hence, the given binary tree is not a binary search tree due to node e.

For modifying the tree so as to make it a binary search tree we would remove the node e from the left subtree and join it to node c and make it the left child of c.

Here is the Diagram:

DatePage no: Originat- 5 rec Violods the Property of ter modificationi 9 5 (17

1.2:

The Tree after inserting the node with key=18 in the corrected tree will look like below:

dt e. afiea dnserking

1.3:

Deletion of any node b in the binary search tree will be done as follows:

Date: L-L-Page no: nochb with -Key. te fi Inorder Sutc esho of node b Cl dl ヂ Inade elate the noole h uoith key5 cl 3

Add a comment
Know the answer?
Add Answer to:
1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9...
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
  • A student believes that Binary Search Trees possess the following property.

     (a) A student believes that Binary Search Trees possess the following property. Suppose we search for a key and the matching node is a leaf node. Let L be the set of all nodes to the left of the search path, P the set of all nodes on the search path, and R be the set of all nodes to the right of the search path. The student claims that any three keys I ∈ L, p ∈ P, and...

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

  • C++ (Using Binary Search Trees) other methods will result in downvote Implement the binary search tree...

    C++ (Using Binary Search Trees) other methods will result in downvote Implement the binary search tree methods (bst.cpp) for the binary search tree provided in the header file. Test your implementation with the included test. bst.h bst_test.cpp Note: Your implementation must correspond to declarations in the header file, and pass the test. Do not modify these two. I will compile your code against these. If the compilation fails, you will get down vote. bst.h #ifndef BINARY_SEARCH_TREE_H #define BINARY_SEARCH_TREE_H #include <string>...

  • C++ Vectors and Binary Search Trees • Write a program that takes from the user n...

    C++ Vectors and Binary Search Trees • Write a program that takes from the user n integers and stores them a vector of int. Then, create a function insert After that takes first Value and second Value. This function searches for each occurrence of first Value in the vector and insert the second Value after it in the same vector. The first and second values are taken from the user. • Create another function that creates a Binary Search Tree...

  • Data Structures and Algorithms What is the: a. maximum number of levels that a binary search...

    Data Structures and Algorithms What is the: a. maximum number of levels that a binary search tree with 100 nodes can have? b. minimum number of levels that a binary search tree with 100 nodes can have? c. maximum total number of nodes in a binary tree that has N levels? (Remember that the root is level 0.) d. maximum number of nodes in the Nth level of a binary tree? e. number of ancestors of a node in the...

  • Consider the B+ tree index shown in Figure 1. Each intermediate node can hold up to...

    Consider the B+ tree index shown in Figure 1. Each intermediate node can hold up to five pointers and four key values. Each leaf can hold up to four records, and leaf nodes are doubly linked as usual, although these links are not shown in the figure. Answer the following questions. Show every step of the insertion and explain the process. 34.21-4 ostas 704 94 986 99-100-105 944954964974 LS Figure 1. (1). Insert a record with search key 109 into...

  • C++ Binary Search Trees C++ PART B Now We Insert node 20. Is the tree balanced?...

    C++ Binary Search Trees C++ PART B Now We Insert node 20. Is the tree balanced? If not, what is the point of Imbalance and BF of that node? Consider the BST in the previous question, but before the insert of node 31. Here it is again: Sa 25 What is the BF of node 50? Is the tree balanced? If not, what is the point of imbalance, and the BF of that node?

  • IN JAVA 2 A Binary Search Tree The goal of this lab is to gain familiarity...

    IN JAVA 2 A Binary Search Tree The goal of this lab is to gain familiarity with simple binary search trees. 1. Begin this lab by implementing a simple class that represents a "node” in a binary search tree, as follows. public class MyTreeNode<t extends Comparable<T>> { public T data; public MyTreeNode<T> leftchild; public MyTreeNode<T> rightChild; public MyTreeNode<T> parent; 2. Have the second member of your pair type in the code for the simple binary search tree interface. public interface...

  • Beginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given?

    Trees-related questionsBeginning with an empty binary search tree, what binary search tree is formed when you add the following letters in the order given? J, N, B, A, W, E, TRepresent the following binary tree with an array  What is the result of adding 3 and 4 to the 2-3 tree shown below?Why does a node in a red-black tree require less memory than a node in a 2-3-4 tree?Why can’t a Red-Black Tree have a black child node with exactly...

  • Using Python to solve the question def _put(self,key,val,currentNode): if key < currentNode.key: if currentNode.hasLeftChild(): self._put(key,val,currentNode.leftChild) else: currentNode.leftChild...

    Using Python to solve the question def _put(self,key,val,currentNode): if key < currentNode.key: if currentNode.hasLeftChild(): self._put(key,val,currentNode.leftChild) else: currentNode.leftChild = TreeNode(key,val,parent=currentNode) elif key > currentNode.key: if currentNode.hasRightChild(): self._put(key,val,currentNode.rightChild) else: currentNode.rightChild = TreeNode(key,val,parent=currentNode) Problem 5 Binary Search Trees (30 points) Modify the books implementation of the binary search tree described in chapters 6.10-6.13 so that it handles duplicate keys properly. The BinarySearchTree class implements a binary search tree where every node of the tree contains a key and a corresponding data item (the...

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