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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started