algorithm for ﬁnding best matches in logarithmic expected time,” ACM Transactions on Mathematical Software. • Tree needs to be balanced, e.g. choose median as discriminator value at each partition. • With O(N) median, tree building takes O(k N log N) time. • Single query takes O(log N) time on average, total running time is O(N log N) when Ns ~ N.