actually O(nlogn) sampling - + binary search for each node.