Answered step by step
Verified Expert Solution
Question
1 Approved Answer
QUESTION 3 A 2 - D tree is a binary tree where every node stores a two - dimensional point. Any node at odd level
QUESTION
A D tree is a binary tree where every node stores a twodimensional point.
Any node at odd level has an xcoordinate which is greater than or equal to the x
coordinates of all nodes in its left subtree, and less than the xcoordinates of all nodes in its
right subtree. Similarly, any node at even Jevel has a ycoordinate which is greater than or
equal to the ycoordinates of all nodes in its left subtree, and less than the ycoordinates of
all nodes in its right subtree.
The following is an example D tree containing the points and
shown as a binary tree and in an equivalent graphical representation. The latter
shows how every node of the tree recursively splits the twodimensional space.
y
X Level @
it G
Yo kevelz
XLevel
& B &
z & T
A D tree is implemented by the class:
public class TwoDTree
private class Node
Point p; The point stored in this node.
Node left; Node right; The left and right child nodes.
int level; The level of the node; root is at level
private Node root; Reference to the root of the tree
Here Point is the following class:
public class Point
public double x;
public double y;
Point int x int y
xx;yy;
Give an efficient implementation of the following method of the TwoDTree class:
Point findKthClosestPoint centre, double radius, int k
The arguments of the method are centre and radius, defining a search circle, and a number
k k The method returns the kth closest point to centre, out of those points which are
stored in the tree and are inside the search circle. If the tree contains fewer than k points
inside the search circle then the method returns null.
The implementation should minimise the required memory needed. It should also avoid
searching inside subtrees whose points are guaranteed to be outside the search circle.
Please comment on the time and space performance of your code.
Note that given a circle with centre x yc and radius r:
o The squared distance of a point xy from x yc is: x Xy yo
o Apoint xy is within the circle when: xxyysr
o Avertical line x a crosses the circle when: a X I
o Ahorizontal line y b crosses the circle when: bysr
In your implementation you can use any of the standard generic ADTs:
Stack MaxPriorityQueue
Queue MinPriorityQueue
SymbolTable,Value
L
XSCH
Where Comparabie is the following generic Java interface:
public interface Comparable
int compareToT o Compares this object with the specified object o It returns
a negative integer if this is less than a positive integer
if this is greater than o and zero if this is equal to
You do not need to implement the ADTs you use, but for each one you use you should specify:
An API for the ADT, containing the methods you use in your implementation.
Atight asymptotic upper bound of the worstcase running time of each of the ADT
methods.
A brief English description of a known implementation of the ADT that has the running
time properties you specified above.
Note: class Point does not implement the Comparable interface. You need to define an
additional PointFromCentre class to use as Key in these ADTs. This new class should be able
to compare points with respect to their proximity to a centre point.
C
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