Question

In: Computer Science

Data structure Give three distinct binary search trees for the following data:   1 2 3 4...

Data structure

  1. Give three distinct binary search trees for the following data:   1 2 3 4 5 6 7. One of these trees must have minimum height and another must-have maximum height.
  2. Draw the BSTs that result from each sequence of add operations. (2) a. 10, 20, 30, 40 b. 30, 20, 40, 10 c. 20, 10, 30, 40

Solutions

Expert Solution

Binary Search Tree: We know, a BST is a binary tree with one special property: All nodes on the left of a node is smaller and all on the right is larger than the node itself.

Given data: 1, 2, 3, 4, 5, 6, 7

Random BST:

BST with minimum height:

BST with maximum height:

*********************

For the second part, drawing a BST after every insertion will be extremely strenous. So instead, I'll try to write it in texts.

2 a

Insert 10

BST:

10

Insert 20

BST:

10

   20

Insert 30

BST:

10

   20

      30

Insert 40

BST:

10

   20

      30

         40

2 b

Insert 30

BST:

30

Insert 20

BST:

   30

20

Insert 40

BST:

   30

20 40

Insert 10:

BST:

      30

   20 40

10

2 c

Insert 20

BST:

20

Insert 10

BST:

   20

10

Insert 30

BST:

   20

10 30

Insert 40

BST:

   20

10 30

         40

In case of any doubt drop a comment and I'll surely get back to you.

Please give a like if you're satisfied with the answer. Thank you.


Related Solutions

Data structure Give three distinct binary search trees for the following data:   1 2 3 4...
Data structure Give three distinct binary search trees for the following data:   1 2 3 4 5 6 7. One of these trees must have minimum height and another must-have maximum height. Draw the BSTs that result from each sequence of add operations. (2) a. 10, 20, 30, 40 b. 30, 20, 40, 10 c. 20, 10, 30, 40
Considering the following different search trees, binary search trees, AVL trees, red-black trees, and others. Compare...
Considering the following different search trees, binary search trees, AVL trees, red-black trees, and others. Compare their advantages and disadvantages, running times, etc
Question 1: Processing Compound Data: Binary Trees A binary tree is a tuple with the following...
Question 1: Processing Compound Data: Binary Trees A binary tree is a tuple with the following recursive structure   ("btree", [val, left_tree, right_tree]) where first part of the tuple is a string "btree" and second part of the tuple is a list in which val is the value at the root and left_tree and right_tree are the binary trees for the left and right children or ("btree",[]) for the empty tree.   (A) Implement a binary tree ADT. Type Name Description Create...
Binary Search Trees with Lazy Deletion Implement binary search tree class with lazy deletion that has...
Binary Search Trees with Lazy Deletion Implement binary search tree class with lazy deletion that has TreeNode as nested class in Java. Design the class, TreeNode to have following class variables: int key; // All Keys are in the range 1 to 99 TreeNode leftChild; TreeNode rightChild; boolean deleted; Your program method must have routines to do the following operations. 1. insert //Should insert a new element to a leaf node. If new element is aduplicatethen do nothing. If the...
Prerequisite Knowledge Understand binary search tree structure Understand binary search tree operations Understand binary search tree...
Prerequisite Knowledge Understand binary search tree structure Understand binary search tree operations Understand binary search tree worst case and best case time. Learning Outcomes Describe AVL tree structure Trace and implement AVL tree operations Explain and prove AVL tree performance
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h....
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h. BST.h code below. CPP code also provided for reference, nothing to be changed on cpp code. #include #include "BSTNode.h" using namespace std; #ifndef BST_H_ #define BST_H_ class BST { public: BSTNode *root; int size; BST() { root = NULL; size = 0; } ~BST() { if (root != NULL) deepClean(root); } BSTNode *search(int key) { // complete this method } BSTNode *insert(int val) {...
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h....
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h. BST.h code below #include <iostream> #include "BSTNode.h" using namespace std; #ifndef BST_H_ #define BST_H_ class BST { public: BSTNode *root; int size; BST() { root = NULL; size = 0; } ~BST() { if (root != NULL) deepClean(root); } BSTNode *search(int key) { // complete this method } BSTNode *insert(int val) { // complete this method } bool remove(int val) { // complete this...
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h....
In C++, dealing with Binary Search trees. Implement search, insert, removeLeaf, and removeNodeWithOneChild methods in BST.h. BST.h code below #include <iostream> #include "BSTNode.h" using namespace std; #ifndef BST_H_ #define BST_H_ class BST { public: BSTNode *root; int size; BST() { root = NULL; size = 0; } ~BST() { if (root != NULL) deepClean(root); } BSTNode *search(int key) { // complete this method } BSTNode *insert(int val) { // complete this method } bool remove(int val) { // complete this...
Derive a recurrence for the number of degenerate binary search trees that can be generated from...
Derive a recurrence for the number of degenerate binary search trees that can be generated from a given sequence of n distinct elements. Recall that degenerate binary search tree contains no branches and thus is structurally similar to a linked list. You must make an argument to justify each component of your recurrence. Remember that all recurrences have base cases so do not forget to include a base case.
Research the topic of binary search trees. Write a brief summary of your understanding of this....
Research the topic of binary search trees. Write a brief summary of your understanding of this. Design a simple program, using pseudocode, that performs a search of a binary search tree.. In your own words, explain how a binary search tree works using graph theory terminology. Construct a binary search tree for any alphabetically ordered list of five words. Represent it visually as a graph. Discuss any characteristics you note about the graph you created in part (d). In your...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT