chap advanced tree structures private kdnode findmin(kdnode rtint descrimint levelkdnode temp temp int[key nullint[key nullif (rt =nullreturn nulltemp findmin(rt left()descrim(level+ )% )if (temp !nullkey temp key()if (descrim !leveltemp findmin(rt right()descrim(level+ )% )if (temp !nullkey temp key()if ((temp =null|((temp !null&(key [descrimkey [descrim]))temp temp key key /nowtemp has the smaller value int[rtkey rt key()if ((temp =null|(key [descrimrtkey[descrim])return rtelse return temp figure the - tree findmin method on levels using the minimum value' discriminatorbranching is to the left on other levelsboth children' subtrees must be visited helper function min takes two nodes and discriminator as inputand returns the node with the smaller value in that discriminator note that we can replace the node to be deleted with the least-valued node from the right subtree only if the right subtree exists if it does notthen suitable replacement must be found in the left subtree unfortunatelyit is not satisfactory to replace ' record with the record having the greatest value for the discriminator in the left subtreebecause this new value might be duplicated if sothen we would have equal values for the discriminator in ' left subtreewhich violates the ordering rules for the - tree fortunatelythere is simple solution to the problem we first move the left subtree of node to become the right subtree ( we simply swap the values of ' left and right child pointersat this pointwe proceed with the normal deletion processreplacing the record of to be deleted with the record containing the least value of the discriminator from what is now ' right subtree assume that we want to print out list of all records that are within certain distance of given point we will use euclidean distancethat ispoint is defined to be within distance of point if (px nx ) (py ny ) < more efficient computation is (px nx ) (py ny ) < this avoids performing square root function