Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * * * Find all elements within a certain distance from the given data. * Distance means the number of edges between two nodes
Find all elements within a certain distance from the given data.
"Distance" means the number of edges between two nodes in the tree.
To do this, first find the data in the tree. Keep track of the distance
of the current node on the path to the data you can use the return
value of a helper method to denote the current distance to the target
data but note that you must find the data first before you can
calculate this information After you have found the data, you should
know the distance of each node on the path to the data. With that
information, you can determine how much farther away you can traverse
from the main path while remaining within distance of the target data.
Use a HashSet as the Set you return. Keep in mind that since it is a
Set, you do not have to worry about any specific order in the Set.
This must be implemented recursively.
Ex:
Given the following AVL composed of Integers
elementsWithinDistance should return the set
elementsWithinDistance should return the set
elementsWithinDistance should return the set
@param data the data to begin calculating distance from
@param distance the maximum distance allowed
@return the set of all data within a certain distance from the given data
@throws java.lang.IllegalArgumentException if data is null
@throws java.util.NoSuchElementException is the data is not in the tree
@throws java.lang.IllegalArgumentException if distance is negative
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