educative.io

How is quadtree search working with place ID as partition key?

We start with assuming a segment lives on a quadtree and then sub segments live on the leaf nodes of quadtree if the segment has too many place. But how does a quadtree design work with place-ID as partition key? We can no longer search the leaf nodes for cafes in nearby segments because the neighboring leaf nodes might not have nearby cafes since place IDs would be random uniquely generated numbers living on different quadtrees. So two places in the same or neighboring segment might be on 2 quadtrees.

Hi Joseph,

You raised a valid point. We’ll surely revamp this lesson in our next iteration. However, for your question, here’s the proposed solution:

  • Location-based Partitioning: Instead of using place IDs, we’ll partition the quadtree based on geographic location (e.g., latitude and longitude). This ensures nearby places are grouped within the same or neighboring segments in the quadtree.
  • Searching nearby places: We’ll perform a range query on the quadtree based on the user’s location and desired radius to search nearby places. This efficiently retrieves all segments within the search area containing potential places of interest.
  • Place Lookup: Once we have the relevant segments from the range query, we’ll use the place IDs within those segments to look up detailed place information.

Thank you.