educative.io

Educative

What will be the search workflow?

What will be the search workflow? We will first find the node that contains the user’s location. If that node has enough desired places, we can return them to the user. If not, we will keep expanding to the neighboring nodes (either through the parent pointers or doubly linked list) until either we find the required number of places or exhaust our search based on the maximum radius.

Is the code below the main idea of how we will use the quad tree? We will keep traversing the tree until we step out of the radius. For each of the grids that we find, we will get their corresponding places from the hash table and get information about the places from the database.

output = []
while true():
  if within_radius(node):
    break
  node = get_parent(node)
  for c in node.children():
    output.append(c)