Given a set of points in a form of (x, y, z), and a set of spheres in a form of (x, y, z, radius).
The goal is, for each sphere, to count the number of points within the sphere.
I compared the Euclidean distance of the center of the sphere and the point against the radius of the sphere, and this algorithm takes O(N*M) time complexity where N, M are the numbers of points and spheres respectively.
I tried to exclude points outside the box of (x ± r, y ± r, z ± r), but it doesn't improve the calculation time at all.
So I studied some data structures like segment tree, quadtree, octree & k-d tree, but I had a hard time applying them to my goal.
How can I downgrade the time complexity to O(NlogM), O(MlogN), or something else?