My first instinct was to just say 'sum all pairwise distances and divide' but then I started second-guessing myself on what 'average' even means here.
Start by clarifying the definition of 'average distance' and the scope (e.g., all city pairs, nearest neighbors, or a sample). Then outline a method to compute pairwise distances using geographic coordinates and discuss computational challenges and optimizations for large datasets.
Pro tip: Mention that for large numbers of cities, computing all pairwise distances is O(n^2) and may be infeasible; instead, consider sampling or using spatial indexing to approximate the average. Also, highlight the importance of using the Haversine formula for accurate great-circle distances.
Ask whether 'average distance' means average over all pairs of cities, average distance to nearest city, or something else. Also confirm the set of cities and whether we need road distance or straight-line distance.
Decide between Euclidean, Manhattan, or Haversine (great-circle) distance. For geographic coordinates, Haversine is most accurate for straight-line distances.
For n cities, compute distances for all n*(n-1)/2 pairs. Use vectorized operations or spatial libraries to speed up computation.
Sum all pairwise distances and divide by the number of pairs to get the average distance.
For large n, discuss sampling, spatial indexing (e.g., KD-trees), or approximate methods. Also consider if the average should be weighted by population or other factors.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.