algorithm - Efficient way to filter a number of things -


there list of venues. each venue has price attached given, , latlon. user enters max distance , max price, , app returns list of venues fit criteria. distance needs calculated on query, can make sort of structure using price or given latlons. know how figure out in o(n) - traverse list of restauraunts, adding them result if fit criteria.

is there way more efficiently? i'm thinking making bst using price key (which can calculated before runtime), cutting off section of bst that's on price limit, , iterating through in bst, still in o(n), right?

one way think problem treat multidimensional range search problem. each venue can thought of point in three-dimensional space given longitude, latitude, , price. if want find venues within radius of given point price @ amount, you're searching points in cylinder given center , radius upper , lower bounds max price , 0, respectively.

you might want consider using multidimesional search tree structure k-d tree or r-tree solve problem. once have structure, search structure bounding box of cylinder list of candidate points. then, test each point in box see if it's inside cylinder. assuming points evenly distributed, you'll find π / 4 fraction of them in cylinder, won't waste effort.


Popular posts from this blog