Data Structures19 sections · 729 units
Open in Course

Why Dual Sorting Works

The scanning trick

When p<midp < \text{mid}, all center intervals contain mid, so they extend at least to mid. You only need to check if they extend left far enough to reach pp.

By sorting center intervals by low endpoint, you scan from smallest low upward.

Once we hit an interval with low>p\text{low} > p, all remaining intervals also have low>p\text{low} > p (sorted order), so you stop.

Similarly, when p>midp > \text{mid}, you sort by high endpoint and scan from largest high downward.

This scanning trick is why we get O(logn+k)O(\log n + k) instead of O(lognm)O(\log n \cdot m) where mm is the number of center intervals. You only scan intervals that overlap.