kdtree data.txt 1 < queries.txt > out1.txtthe output resulting from the queries in the query file queries.txt gives the resulting output of results out1.txt .
kdtree data.txt 2 < queries.txt > out2.txthere is the resulting output out2.txt .
Note that you still have to analyze the time to build a kd-tree with n points.
In particular, implementing the nearest neighbor query by repeatedly performing orthogonal range queries with rectangles of varying sizes is not a good idea. This is because it is not efficient and because the query rectangles are selected in an ad-hoc manner. You will lose points for such a solution.