Basic algorithm to calculate overlaps.