Smallest Quadrilateral

Smallest Quadrilateral

In 𝐄𝐱 𝟏.πŸπŸ–\textbf{Ex 1.18} of Jay Cummings’ Proofs_\underline{Proofs}, the reader is asked to show (via. pigeonhole principle) that given 19 random points from the interior of a 6Γ—46 \times 4 box, the smallest quadrilateral will have an area no larger than 44. Let’s look at a related problem.

𝐍.𝐁\textbf{N.B} β€” β€œSmallest Quadtrilateral” sounds like a LeetCode problem. Yuck.

Given nn points selected from [0,1]2\left[0, 1 \right]^{2}, can we come up with an algorithm that finds the smallest quadrilateral in β€œreasonable” time? The naive solution runs in (n4)∼O(n4){n \choose 4} \sim O\Big(n^4) time, but we can do better by ignoring subsets of points that will not produce a near-optimal result. Consider the following algorithm:

  1. Duplicate the points and sort them two separate arrays (AxA_x, AyA_y) by their π‘₯\textit{x} and 𝑦\textit{y} values respectively.

  2. Locate each point (pip_i) in AxA_x and AyA_y and access the points β€œnear” pip_i. We’ll use this set to compute the smallest quadrilateral which includes pip_i as a vertex. Formally, we build a set SiS_{i}:

    Si={pj∣min(dx(pi,pj),dy(pi,pj))≀3}\begin{equation} S_i = \left\{p_j \mid \operatorname{min}\left( \ d_x\big(p_i, p_j), \ d_y\big(p_i, p_j) \ \right) \leq 3 \right\} \end{equation}

    Where dxd_x and dyd_y return the distance between the indexes of two points in AxA_x or AyA_y. Collecting pip_i and its neighbors in either direction guarantees 7≀|Si|≀137 \leq \lvert S_i \rvert \leq 13.

  3. With the size of SiS_i bounded, we can apply the naive algorithm on SiS_i and find the smallest quadrilateral which includes pip_i by enumerating no more than (123){12 \choose 3} quadrilaterals.

  4. We proceed by performing π’π­πžπ© 𝟐\textbf{Step 2} and π’π­πžπ© πŸ‘\textbf{Step 3} for each of nn points and storing the minimal area (and optionally the associated points) observed thus far. After nn iterations, the result is our minimal quadrilateral.

Overall, this algorithm runs in π’ͺ(nln(n))\mathcal{O}\big(n\ln\big(n)) and is limited by the performance of the sort in π’π­πžπ© 𝟏\textbf{Step 1}. In π’π­πžπ© 𝟐\textbf{Step 2}, we can locate pip_i in either array in π’ͺ(log(n))\mathcal{O}\big(\log\big(n)) and locate points β€œnear” pip_i in π’ͺ(1)\mathcal{O}\big(1). In π’π­πžπ© πŸ‘\textbf{Step 3} we can compute the size of all quadrilaterals in π’ͺ(1)\mathcal{O}\big(1). The constant in π’π­πžπ© πŸ‘\textbf{Step 3} may be a little too large for comfort, but can be probably be reduced with more careful study.