Suppose we have n points in 2D space in convex position. There are precisely choose(n, k) different convex k-gons (non-degenerate). Is there any existing algorithm that runs in O(n log n) time (for a fixed k) which counts the number of polygons containing the origin?
I tried to look for any such algorithms in the literature, but only managed to find an algorithm for k=3.
Here is a sweep line algorithm.
First, count up polygons. Then sweep a line around, removing polygons not containing the origin when the polygon is fully in view, then has its first point removed.
For fixed
kthis is aO(n log(n))algorithm. For largekthe bottleneck is repeatedly calculatingchoose(m, k-1)for the subtraction. That can be sped up by creating a lookup table for it inO(n). (Left as an exercise for the reader.)