Klee's Algorithm (Length Of Union Of Segments of a line) - GeeksforGeeks
Given starting and ending positions of segments on a line, the task is to take the union of all given segments and find length covered by these segments.
Examples:
Input : segments[] = {{2, 5}, {4, 8}, {9, 12}} Output : 9 segment 1 = {2, 5} segment 2 = {4, 8} segment 3 = {9, 12} If we take the union of all the line segments, we cover distances [2, 8] and [9, 12]. Sum of these two distances is 9 (6 + 3)
The algorithm was proposed by Klee in 1977. The time complexity of the algorithm is O (N log N). It has been proven that this algorithm is the fastest (asymptotically) and this problem can not be solved with a better complexity.
Read full article from Klee's Algorithm (Length Of Union Of Segments of a line) - GeeksforGeeks
No comments:
Post a Comment