Wait, What?
Sorting intervals by their starting point is not enough to answer overlap queries efficiently.
Interval trees teach a powerful algorithmic pattern: preserve an ordinary search-tree order, then augment each node with extra information that lets the search safely skip whole subtrees. For overlap queries, the crucial summary is usually the maximum interval endpoint stored in a subtree.
Quick Answer
Learn interval trees through interval-overlap predicate → BST order by low endpoint → subtree max-high augmentation → pruning rule → insertion/deletion maintenance → reporting variants.
1. Write the Overlap Predicate First
Two closed intervals [a,b] and [c,d] overlap when a ≤ d and c ≤ b. Before touching the tree, practise this predicate on boundary cases: touching endpoints, nested intervals, disjoint intervals and equal intervals. Many implementation errors begin here.
2. Keep an Ordinary Ordering Invariant
Order nodes by each interval’s low endpoint. This gives the tree a conventional search structure. The interval tree is not correct because of the augmentation alone; it remains a search tree first.
3. Add the Max-High Summary
Each node stores the largest high endpoint appearing anywhere in its subtree. That one number gives the search a certificate about whether the left subtree could possibly contain an interval reaching far enough to overlap the query.
4. Learn the Pruning Rule
If the current interval overlaps the query, stop or report it. Otherwise, inspect the left child’s max-high value. If it is at least the query’s low endpoint, the left subtree may contain an overlap; search there. If it is smaller, no interval in that subtree can reach the query, so prune it and move right.
5. Trace Why the Pruning Is Safe
Do not memorise “go left if max is big enough.” Ask what the summary means. If every interval in the left subtree ends before the query starts, then overlap is impossible there. The pruning rule is therefore a logical consequence of the stored summary, not a heuristic.
6. Updates Must Repair the Augmentation
After insertion, deletion or tree rotations, recompute max-high values on affected nodes. If the underlying tree is balanced, both the ordering invariant and the augmentation must survive rebalancing. This is where many “working” implementations silently become incorrect after updates.
7. One Overlap Versus All Overlaps
Finding any overlapping interval is a different output contract from reporting every overlap. Output-sensitive reporting may need to explore multiple branches. Learners should state the required output before claiming a complexity bound.
Common Failure States
- Using the wrong boundary convention for overlap.
- Forgetting to update subtree maxima after rotations.
- Pruning from a node’s endpoint rather than the subtree maximum.
- Claiming one-overlap complexity for an all-overlaps query.
- Confusing interval trees with segment trees or ordinary range-sum trees.
Practice Ladder
- Classify interval pairs as overlapping or disjoint.
- Build max-high values on a fixed tree.
- Trace a successful overlap search.
- Trace a query where an entire subtree is pruned.
- Insert an interval and repair all affected summaries.
- Compare interval trees, segment trees and sweep-line methods for different workloads.
Learning Hall Boundary
This article owns dynamic interval-overlap search through tree augmentation. The existing range-query and spatial-index articles remain separate because their problem contracts and structures differ.
Professional rule: understand an interval tree when you can derive the pruning condition from the subtree summary and maintain that summary correctly through every structural update.
