I am looking into this problem:
Let's assume we have N segments on the X-axis with different start and end points. This is described with the next data structure:
[(start1, end1),..., (startN, endN)]
Now we want to calculate the whole size of such segments, but overlaps should be not be double counted.
Example
input: [(0,3),(1,2), (6,7)]
output: 4
Because segment (1,2) overlaps with segment (0,3), the distance between 0 and 3 is just 3, and then between 6 and 7 it is 1. So 3+1 = 4.
Question
Is there an algorithm to make this calculation for large input sizes?