Apex › Storage & databases

Interval tree

Answer "which intervals overlap this range?" in O(log n + k) instead of scanning all of them — for calendars, genome features, firewall port ranges. A BST keyed by low endpoint, augmented so each node stores its subtree's maximum high endpoint, which lets a search prune whole subtrees that can't reach the query. Slide the query range and watch the overlaps light up and the pruned subtrees dim.

More in Storage & databases