Skip to content

Improve algorithm to find the N closest cities to current location #28

@amaury1093

Description

@amaury1093

Summary

The current algorithm for find the N closest cities to the current location is very naive. We could optimize it.

Problem Definition

If you go to the page of a city (example here), there's a ranking section, which shows the 6 closest cities to the current location, and their cigarettes information.

Screenshot 2020-10-25 at 19 27 48

The current algorithm to calculate these closest cities is the following:

This algorithm is not optimal (O(n^2)). It's okay for 1000 cities, but there are surely better way to find the closest N cities around the current location.

Potential Solutions

  • data structures such as r-tree, quad-tree or k-d tree

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions