Brute-force and plane-sweep algorithms for calculating segment intersections for Geometric Algorithm (Course code: 2IMA15)
Let
horizontal segments n
a1 a1' b1
...
an an' bn
vertical segments m
c1 d1 d1'
...
cm dm dm'
The first line in the input contains the text horizontal segments and an integer
Max priority queue to store events, AVL tree to store status, 1d range search
This figure shows three generated datasets when
The three subplots above represent the results of the SHORT, MEDIUM, and LONG experimental groups, respectively. The three subplots below are enlargements of sections from the above subplots, specifically focusing on the range where
- As the number of line segments increases, the running time of the brute-force algorithm grows at a much faster rate compared to the plane-sweep algorithm. Our method significantly outperforms the brute-force approach.
- By comparing the three subplots above, it is observed that the number of intersections does not significantly impact the running time. This effectively validates our algorithm's time complexity of
$O((m+n)log(m+n))$ , indicating that it is independent of the number of intersections$k$ . - From the three subplots below, it can be discerned that when the dataset is small, the running time of the brute-force is superior to that of the plane-sweep. However, as the dataset size increases beyond approximately 140, the running time of the plane-sweep algorithm becomes less than that of the brute-force implementation.
- The curves of the brute-force and plane-sweep intersect at a point, indicating that the running times of both algorithms are equal at this juncture. In the SHORT, MEDIUM, and LONG datasets, the x-coordinate of this intersection point is respectively 100, 130, and 140. As the length of the segments increases, leading to more intersections between them, the intersection point of the two curves occurs later.
