Greedy kth Nearest Neighbor Sampling

The knnsample function takes a finite metric space as input and produces a subset with the property that the distance to the second nearest sample is a constant factor approximation to the distance to the kth nearest input point. Such a sample is called kth nearest neighbor sample. Moreover, the output is given in greedy order.