CS 411 Fall 2025 > Outline & Supplemental Notes for October 6, 2025
CS 411 Fall 2025
Outline & Supplemental Notes
for October 6, 2025
Outline
Multiplication (cont’d) [L 5.4]
See the October 3, 2025 lecture notes.
Closest Pair & Convex Hull [L 5.5]
- Closest Pair
- Recall problem: points in the plane
- For simplicity we will assume no two points share the same \(x\)- or \(y\)-coordinates.
- Brute-force algorithm: \(\Theta(n^2)\)
- Efficient algorithm using Divide and Conquer?
- Ideas
- Split list & recurse on each half.
- Might still have close points near center strip.
- Issues
- How to split list efficiently. Solution: have \(x\)-coordinate-sorted list.
- Can central strip be checked efficiently? Solution: Only need to check each point against next \(5\) when the points are ordered by increasing \(y\) coordinate. (See Supplemental Notes.)
- How to create a subcollection of points efficiently. Solution: There are many ways to do this. Could have master list of points, sorted lists of indices to master list. Create subcollection by copying into smaller lists of indices.
- Ideas
- Algorithm
- Make presorted lists: list sorted by \(x\) and list sorted by \(y\).
- Recursive sub-algorithm
- Base case: \(2\) or \(3\) points.
- Split list by \(x\), recurse on both parts, let \(d\) be min distance found.
- Center strip is \(2d\) wide. Traverse by increasing \(y\)-coordinate, check each point against next \(5\). (See Supplemental Notes.)
- Analysis
- Master Theorem gives \(\Theta(n\log n)\) for \(n\) points.
- Presorting does not affect order of algorithm.
- Recall problem: points in the plane
- Convex Hull
- Recall problem: points in the plane
- Brute-force algorithm: \(\Theta(n^3)\)
- Efficient algorithm using Divide and Conquer?
- Ideas
- Given two points \(A\), \(B\) on boundary of convex hull, a point \(C\) that is farthest from line through \(A\), \(B\) must also lie on boundary.
- Then recurse using \(A\), \(C\) and using \(B\), \(C\).
- Issues
- Need two points to start the recursion. Solution: Use points with greatest & least \(x\)-coordinates.
- What if a point lies exactly on a line between two others? Problems with floating-point equality? Solution: GGC suggests using exact rational arithmetic (available in C++; standard with some programming languages, e.g., Python, Haskell).
- Ideas
- Algorithm (Quickhull—Eddy 1977, Bykat 1978)
- Let \(A\), \(B\) be the points with greatest and least \(x\)-coordinates. Mark \(A\), \(B\) as lying on boundary of convex hull. Call recursive sub-algorithm with \(A\), \(B\), points on one side of line through them. The call with \(A\), \(B\), points on other side.
- Recursive sub-algorithm
(given two points \(A\), \(B\) on boundary of convex hull
and other points, all on same side of line through \(A\), \(B\))
- Base case: \(A\), \(B\) are only points.
- Find point \(C\) farthest from line through \(A\), \(B\). Mark \(C\) as lying on boundary of convex hull.
- Recurse with \(A\), \(C\), points outside.
- Recurse with \(B\), \(C\), points outside.
- Analysis
- Worst case: \(\Theta(n^2)\) for \(n\) points.
- What about average case? We need to be very careful about what average means. If we have a randomly generated set of points in a convex region, each point is uniformly distributed over the region, and the points are generated independently, then the average-case time is known to be \(\Theta(n)\). But the analysis is quite tricky.
Supplemental Notes
More on the Divide and Conquer Closest-Pair Algorithm
This section is based in part on work done by my former graduate student Jason Bright and myself.
The Central Strip
When processing the central strip in the closest-pair algorithm, we order the points in ascending order by y-coordinate. The text gives a simple argument showing that we only need to check distances between each point and the next \(7\) points in the ordering. Then it states that it is enough to check the next \(5\).
In fact, we only need to check the next \(3\) points. This is difficult to prove—but it is true.
Checking only the next \(2\) is not enough, as illustrated by the following set of points: \(\left\{(1,-3),(-6,-2),(6,2),(-1,3)\right\}\).
The Base Case
We previously studied a Brute Force algorithm for the Closest Pair Problem. This is \(\Theta(n^2)\), while the Divide and Conquer algorithm is \(\Theta(n\log n)\). However, for small-ish sets of points, the Brute Force algorithm is faster. The crossover point at which the Divide and Conquer algorithm becomes faster depends on various implementation details, but it is somewhere upwards of \(40\) points.
Thus, we can get better performance from the Divide and Conquer algorithm if we use as a base case, not sets of size \(2\) or \(3\), but sets of size at most \(40\)—or perhaps a greater size. The base case is then handled by the Brute Force algorithm.
More on Finding the Convex Hull
Quickhull is another “quick—” algorithm with a fast average case but a slow worst case. We have mentioned how the technique of introspection can be used with the Quickselect and Quicksort algorithms to construct an algorithm that is very fast in the average case and pretty fast in the worst case. Can introspection give us a fast convex-hull algorithm?
Yes, it can. As you might expect, we call the resulting algorithm Introhull. As in the earlier introspection examples, we run Quickhull, keeping track of the recursion depth; we switch to an algorithm with a faster worst case if the depth exceeds some limit. What algorithm should that be? There are known algorithms that find the convex hull of a set of \(n\) points in the plane in time \(\Theta(n\log n)\), example, Plane Sweep (A. M. Andrew 1979), which we will not discuss in any detail. Using this as our fallback algorithm gives us an Introhull with worst-case time \(\Theta(n\log n)\) and average-case time \(\Theta(n)\), where average has the meaning described earlier.