Suppose there are multiple intervals on $\mathbb{R}$, e.g., $[0,0.5]$, $[0.4,1]$, $[1.5,2]$, the union of them should be $[0,1]$ and $[1.5,2]$. Is there a specific datastructure (or algorithm) for computing such union?
A variation of this problem is to union intervals on cyclic domain, for example, angles from $-\pi$ to $\pi$. Now, $[-\pi/2, \pi/2]$ and $[\pi/2, -\pi/2]$ present different intervals of angles.
I have coded a brute force algorithm, however, I am wondering there already exist studies on this.