I have the zip codes for the US and their population. I need to calculate the weighted center. I have tried finding the zip code with the minimum
sum(distance_to_zip * zip_population)
This works but is slow. With 30,000 zip codes there are two loops, so 900 million calculations. I've tried to optimize by sorting based on distance from the middle, and stopping the inner loop once the value hits the current lowest value. This helps, but it's still too slow.
Is there a faster algorithm for calculating the weighted center?
Note: I am writing my own code, I'm not looking to do this in a GIS package.