Question: Please code in JAVA all TODO sections: package algs 3 2 . kdtree; import algs 1 2 . Point 2 D; import algs 1 3
Please code in JAVA all TODO sections:
package algskdtree;
import algsPointD;
import algsQueue;
import stdlib.;
a set of points implemented as kdtree
public class KdTree
private static class Node
TODO
private Node root;
construct an empty set of points
public KdTree
TODO maybe nothing to do here... in which case you can remove this and use the default constructor
is the set empty?
public boolean isEmpty
TODO
return false;
add the point p to the set if it is not already in the set
public void insertPointD p
TODO
does the set contain the point p
public boolean containsPointD target
TODO
return false;
all points in the set that are inside the target rectangle
public Iterable rangeRectHV target
TODO
return new Queue;
a nearest neighbor to target point; null if empty
public PointD nearestPointD target
TODO
return new PointD ;
draw all of the points to standard draw
for xnode, use red line to draw the division between leftright
for ynode, use blue line to draw the division between topbottom
see the writeup for examples
public void draw
TODO
some test code
public void toGraphviz GraphvizBuilder.nodesToFile root;
private static void insertPoints KdTree kdtree, double xoffset, double yoffset
kdtree.insert new PointD xoffset, yoffset;
kdtree.insert new PointD xoffset, yoffset;
kdtree.insert new PointD xoffset, yoffset;
kdtree.insert new PointD xoffset, yoffset;
kdtree.insert new PointD xoffset, yoffset;
public static void main String args
KdTree kdtree new KdTree ;
insertPoints kdtree; after this there should be points
insertPoints kdtree; after doing it twice there should still be
insertPoints kdtree; this should add more points
insertPoints kdtree; this should add more points
kdtree.insert new PointD;
kdtree.insert new PointD;
kdtree.insert new PointD;
kdtree.insert new PointD;
kdtree.insert new PointD;
kdtree.insert new PointD;
kdtree.insert new PointD;
kdtree.insert new PointD;
PointD mid new PointD ;
PointD less new PointD ;
PointD more new PointD ;
kdtree.insert mid;
kdtree.insert less;
kdtree.insert more;
StdOut.println kdtreecontains less;
StdOut.println kdtreecontains more;
StdOut.println kdtreerange new RectHV ;
StdOut.println kdtreenearest less;
StdOut.println kdtreenearest more;
StdOut.println kdtree;
kdtree.toGraphviz ;
kdtree.draw ;
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
