title: 2d Tree Nearest Neighbor Algorithm Clarification
body: <p>I am trying to implement a recursive nearest neighbour algorithm for a 2d-Tree.
  Recursion (and unwinding recursion) is still kind of confusing for me and the best pseudocode I have found is from this StackOverflow question:</p>
  
  <p><a href="https://stackoverflow.com/questions/28028618/2d-kd-tree-and-nearest-neighbour-search">2D KD Tree and Nearest Neighbour Search</a></p>
  
  <p>However the answer uses a "Median" value, which I am not sure how to compute. Also the wikipedia article on kd-trees has a nearest neighbour pseudo code that does not use a median value.</p>
  
  <p>I would like to know if it is possible to construct a recursive version of the Nearest Neighbours algorithm without using a median value. If anyone can provide me with pseudo code for this I will be grateful.</p>