Question: / * * * 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
