Question: Must be done in java: LIBRARIES available to USE: java.util.linkedlist, java.util.stack, java.util.queue Objective: The goal of this assignment is to practice the use of binary

Must be done in java: LIBRARIES available to USE: java.util.linkedlist, java.util.stack, java.util.queue

Objective: The goal of this assignment is to practice the use of binary search trees.

Assignment: Write several recursive methods related to trees:

-a method that, given a binary search tree, returns its smallest element;

-a method that, given a binary search tree, returns its largest element;

-a method that, given a binary search tree, returns the total number of elements in the tree;

-a method that, given a binary search tree, returns its height;

-a method that, given an element and a binary search tree, checks whether this element belongs to this tree;

-a method that, given an element and a binary search tree, adds this element to the tree.

Main idea. For example, to find a given element in a given tree, we do the following. First, we check whether the tree is empty. If the tree is empty, then the given element is not there, otherwise we compare the given element with the root of the tree:

-if the element is equal to the root, we return "true";

-if the element is smaller than the root, we search in the left subtree;

-if the element is larger than the root, we search in the right subtree.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!