Q1: How many levels your binary search tree has (including level 0)? Is the binary search tree you created height balanced?
2.1 Click the animations “Binary
Search Tree”. Click “Insert” button to insert
the following elements in the sequence, “50, 20, 30, 70, 90, 80,
40, 10, 5, 60,
85, 95”.
http://algoanim.ide.sk/index.php?page=showanim&id=44
Q2: What is the insertion process of the binary search tree? The new identical element is inserted as left or right child of the existing same value?
2.3 Fill another identical 65 in the
blank of Insert, and click Insert to insert this
element.
Q3: What is the find process of the binary tree? If we have the multiple appearance of an element, such as 52, can both be found?
2.4 Fill 60 in the blank on the left
of Find button, and click Find to search this
element, we have Figure 4 after it is found. Try again using some
element is
not in the tree, such as 52 in my case.
Q4: What is traverse process and what is the visiting result? What order it is, prefix (Middle->Left->Right), postfix (Left->Right->Middle), or infix (Left->Middle->Right)?
2.5 Click print button to observe the traverse process.
Q5: What is delete process? Which element is selected to replace in the position of 70?
2.6 Click Del to delete 70, we will have Figure 5
Q6: List all the major changes (such as color change, rotations) happening during the insertion process for each value?
3.1 Click the animations “Red/Black
Tree”. Click “Insert” button to insert the
following elements in the sequence, “10, 20, 30, 40, 50, 60, 70,
80, 90”. The
created figure is Figure 6.
http://algoanim.ide.sk/index.php?page=showanim&id=63
Q7 : What is the find process of the red/black tree?
3.2 Fill 60 in the blank on the left of Find button, and click
Find to search this
element
Q1.
This is the tree obtained on inserting the given elements:
The number of levels in the above binary search tree is 5.
No, the above tree is not height-balanced. Its current height is 4, which can be reduced to 3.
Q2.
When inserting a new value 60 in the above tree, the resultant tree is:
Hence, we can see that the new 60 is inserted to the right of the old 60.
Thus, the new identical element is inserted as the right child of the existing same value.
Q3.
When finding the element 60, only its first occurrence is being found. The further occurrences of the same element are ignored.
Thus, if we have multiple appearances of an element, only the first occurrence can be found.
Q4.
The traverse order is infix (Left->Middle->Right) as can be seen by the following order:
Q5.
On deleting the element 70, the tree looks like;
The element 60 is selected to replace in the position of 70. This means that the rightmost element (i.e., the largest element) in the left subtree of the element to be deleted is selected to replace the element. This is the delete process.
Q6.
Below are the screenshots of the tree every time a new element is inserted.
This shows all the major changes (such as color change, rotations) happening during the insertion process for each value.
Q7.
The following picture shows the element 60 being searched in the red-black tree.
The find process is the same as the traditional Binary Search tree. Firstly, the root element is matched with the element to be searched for. If the root element is bigger than the searching element, then the search continues for the left subtree of the current node. If it is smaller than or equal to the searching element, the search continues for the right subtree. If it is equal, we have found the element.
For example, in this case, firstly, 60 is compared with 40. Since 40<=60, the search continues for the right subtree. Now, the root element of the right subtree is 60. It is compared with the element to be searched for, which is also 60. Since both the elements are the same, this is our result.
Hope it helped. If you have any doubts or queries, please feel free to ask in the comments section. If it helped in any way, please consider giving positive ratings.
Q1: How many levels your binary search tree has (including level 0)? Is the binary search tree you created height balanc...
Q1: How many levels your binary search tree has (including level 0)? Is the binary search tree you created height balanced? 2.1 Click the animations “Binary Search Tree”. Click “Insert” button to insert the following elements in the sequence, “50, 20, 30, 70, 90, 80, 40, 10, 5, 60, 85, 95”. http://algoanim.ide.sk/index.php?page=showanim&id=44 Q2: What is the insertion process of the binary search tree? The new identical element is inserted as left or right child of the existing same value? 2.3...
Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate insert operation in binary search tree. Please fill in the missing part for the insert method to make the program work. The expected output should be as follows. 20 30 40 50 60 70 80 Part B: Find Lowest Common Ancestor (LCA) of a Binary Search Tree. According to WikiPedia definition , The lowest common ancestor is defined between two nodes v and...
In C++ I need the printRange function, and the main.cpp program. Thanks. (Binary search tree) Write a function printRange that takes as input a binary search tree t and two keys, k1 and k2, which are ordered so that k1 < k2, and print all elements x in the tree such that k1 <= x <= k2. You can add this function in BinarySearchTree.h (click the link) that we used in the lecture and lab 7. public: void printRange(int k1,...
Hi there, I am working on a binary search tree code in c++. The program must store and update students' academic records, each node includes the student name, credits attempted, credits earned and GPA. I have made some progress with the code and written most of the functions in the .cpp file (already did the .h file) but i am struggling with what to put in the main and how to put an update part in the insert function. I...
Please I need help ASAP Java Programing: Binary Search Tree Fully implement the BST class in Listing 25.4 (on page 961 of the 11th Edition of the text). Design and write a (main) driver program to completely test every method in the BST class to ensure the class meets all its requirements. You should read the Listing 25.5: TestBST.java for an idea of what your program should look like. Listing 25.4 BST.java public class BST> extends AbstractTree { protected TreeNode...
create your own implementation of a Binary Search Tree using the following data structure: public class BinarySearchTreeVertex<E> { public E e; public BinarySearchTreeVertex<K> parent; public BinarySearchTreeVertex<K> left_child; public BinarySearchTreeVertex<K> right_child; } Create a generic class called BinarySearchTree<E> that maintains a BST. This class contains a reference to the root of the BST and provides the functions add() and find(): public class BinarySearchTree<E> { public BinarySearchTreeVertex<E> root = null; public boolean add(E e) {} public boolean find(E e) {} }...
Preliminaries Download the template class and the driver file. Objective Learn how to traverse a binary search tree in order. Description For the template class BinarySearchTree, fill in the following methods: insert - Inserts values greater than the parent to the right, and values lesser than the parent to the left.parameters elem - The new element to be inserted into the tree. printInOrder - Prints the values stored in the tree in ascending order. Hint: Use a recursive method to...
Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods. Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement Element to be found */ int findAll(int...
2 Apply Your Knowledge Reinforce the skills and apply the concepts you learned in this chapter Styling a Webpage Instructions: In this exercise, you will use your text editor to create external, embedded, and inline styles for the Durango Jewelry and Gem Shop home page. You will style the sections of the semantic wireframe header, nav, main, and tooter and a div element that surrounds all of the content to center the content on the page. You will also float...
I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...