Answered step by step
Verified Expert Solution
Link Copied!

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
*50
*/\
*2575
*/\/\
*13377080
*/\\\
*12154085
*/
*10
* elementsWithinDistance(37,3) should return the set {12,13,15,25,
*37,40,50,75}
* elementsWithinDistance(85,2) should return the set {75,80,85}
* elementsWithinDistance(13,1) should return the set {12,13,15,25}
*
* @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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions