Given non horizontal random line segments in $mathbb{R^2}$ in terms of their endpoint coordinates that do not intersect and do not share the same $y$-value in their endpoints, I want to (efficiently) construct a binary tree satisfying the following:
- The root(s) are the upper most segments with no segments above
- Each segment has at most 2 children where one child (black) is the segment that first occurs when drawing a vertical line from the lower endpoint of the parent segment to the $x$-axis
- Analogously, the other child (blue) is the segment we get after the upper endpoint of the parent segment
For illustration, on the left are segments $S_1, ldots, S_7$ and on the right is the corresponding tree with upper endpoint children marked blue
segments and tree
We obviously have to sort the given segments/endpoints in a smart way such that we can construct the tree without naively checking every segment to be a potential child.
We have to distinguish in some way after $y$ coordinates since segments with higher endpoints than both of the endpoints of the segment we are considering cannot be children. Also, if the $x$-coordinate interval of two segments between their endpoints does not overlap, they cannot be connected in our tree.
Since we cannot simultaneously sort after $x$ and $y$, this may suggest that we need two (or more) separate sorting.
Further observations: A segment can only be a child of the lower end, if its lower endpoint is lower than the one of the parent segment.
Although I put in some thought, I can’t seem to get further progress. Is there some criteria that lets me construct the tree I am looking for in efficient time?
JonasFitzgerald is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.