An easy way to solve this problem in O(n) time is to use inversion in a circle.
General Outline
Pick any point O(x,y) from the set to be the origin, and pick a circle of radius r
with your chosen point as center. The calculations will be simplified if all points are translated by an amount (-x,-y) so that the point O becomes the origin.
Once you have chosen an origin and a circle, perform the operation of inversion with respect to your chosen circle to all the other points in the set. In coordinates, we map the point P(x,y) to the new point P' with coordinates (x',y') = (x,y)*r^2/(x^2+y^2)
. The origin O(0,0) goes to the point at infinity.
With the inversion transformation, the problem reduces to finding a line with the required properties (passes through two of the transformed points because a line always passes through the point at infinity; furthermore the line should split the remaining transformed points into two equal sets).
Note that inversion maps the set of 3 collinear and 4 concentric points onto the set of 3 collinear and 4 concentric points, so in the transformed set we have no 3 collinear points and no 4 concentric points.
To construct the circle, we then perform the inverse inversion (which is the same as the original inversion, since inversion in a circle is an involution, a self-inverse transformation). That pulls the line back to a circle passing through the first chosen point and two other points from the original set. Half the remaining points are inside the circle, half outside.
Corresponding Problem with Lines
Now we have reduced the problem to the following: given 2n+2 points in the plane, find a line passing through 2 of the points such that of the remaining 2n points, n are on one side of the line and n are on the other.
We can answer that question in O(n) time as follows. First, we need a single point in the boundary of the convex hull of the set (we don't need the whole convex hull). We can find such a point P by finding the point(s) in the set with coordinates minimum x value, which can be done in O(n) time using the Quickselect algorithm.
Now we know that all our points are in the half-space to the right of P. The idea of the next step is to find the point Q with median angle of all points with respect to the horizontal line h through P. Again, that can be accomplished in O(n) time using the Quickselect algorithm. There can be no two points with the same angle because there cannot be three points which are collinear.
The line PQ passes through two of the points and separates the remaining points R into two equal parts according to whether the angle RPh is greater than QPh or less than QPh (negative angles are below h).
One small problem can potentially arise: if the line passes through the origin, then inversion takes it to another line, not to a circle. However that situation cannot arise because it would mean that we had 3 collinear points in the original set, guaranteed not to be the case by the problem statement.