In of Jay Cummingsβ , the reader is asked to show (via. pigeonhole principle) that given 19 random points from the interior of a box, the smallest quadrilateral will have an area no larger than . Letβs look at a related problem.
β βSmallest Quadtrilateralβ sounds like a LeetCode problem. Yuck.
Given points selected from , can we come up with an algorithm that finds the smallest quadrilateral in βreasonableβ time? The naive solution runs in time, but we can do better by ignoring subsets of points that will not produce a near-optimal result. Consider the following algorithm:
Duplicate the points and sort them two separate arrays (, ) by their and values respectively.
Locate each point () in and and access the points βnearβ . Weβll use this set to compute the smallest quadrilateral which includes as a vertex. Formally, we build a set :
Where and return the distance between the indexes of two points in or . Collecting and its neighbors in either direction guarantees .
With the size of bounded, we can apply the naive algorithm on and find the smallest quadrilateral which includes by enumerating no more than quadrilaterals.
We proceed by performing and for each of points and storing the minimal area (and optionally the associated points) observed thus far. After iterations, the result is our minimal quadrilateral.
Overall, this algorithm runs in and is limited by the performance of the sort in . In , we can locate in either array in and locate points βnearβ in . In we can compute the size of all quadrilaterals in . The constant in may be a little too large for comfort, but can be probably be reduced with more careful study.