r/AskProgramming • u/puremath369 • Apr 11 '19
How does Tinder and Bumble implement nearest neighbors?
I'm looking for a data structure that would allow for efficient look ups of points within a certain radius from another point. That is, given a certain point and a radius, return all points within that radius to the given point. Basically, how does tinder and bumble accomplish this when you find other people X miles from me? I've heard of the K nearest neighbors algorithm but, this is hard because how do I appropriately select K? For example, suppose I select K = 1000 but in reality, k = 5000 would've return results all still within X miles from me. Anyone know of any data structures that can accomplish this efficient searching? It's okay if insertion of the data is not as efficient since searching will be used much more.
11
u/[deleted] Apr 11 '19 edited Apr 11 '19
There are many indexing structures that could be used to make k-Nearest Neighbors faster. You could use KD-trees if the features are indeed geometric coordinates, or you could use something like Orchad Algorithm to quickly eliminate false neighbors. Another way to dismiss false neighbors is to employ lower bounds, which is especially useful if you are using an elastic measure, like DTW.
But notice that the k in k-NN does not relate to miles. It is the number of neighbors you want to retrieve. So if you want the closest match, then it's k=1. Of course, "match" in Tinder is not done geographically, but according to features.
Expanding on Tinder, it doesn't really give you the exact distance. Here's an interesting read (which I regret not to remember enough to summarize here) https://robertheaton.com/2018/07/09/how-tinder-keeps-your-location-a-bit-private/