Question: 2. Step 2 of Algorithm ANY-SEGMENTS-INTERSECT from Lecture 10 sorts the endpoints of the seg- ments in S from left to right. Why does it

 2. Step 2 of Algorithm ANY-SEGMENTS-INTERSECT from Lecture 10 sorts the

endpoints of the seg- ments in S from left to right. Why

2. Step 2 of Algorithm ANY-SEGMENTS-INTERSECT from Lecture 10 sorts the endpoints of the seg- ments in S from left to right. Why does it have to break ties by always putting left endpoints before right endpoints with the same c-coordinate in the sorted list? (2 marks) Algorithm ANY-SEGMENTS-INTERSECT(S), ANY-SEGMENTS-INTERSECT(S) 1 TO 2 sort the endpoints of the segments in S from left to right, breaking ties by putting left endpoints before right endpoints and breaking further ties by putting points with lower y-coordinates first 3 for each point p in the sorted list of endpoints do if p is the left endpoint of a segments then INSERT(T, s) if (ABOVE(T, ) exists and intersects s) or (BELOW (T, s) exists and intersects s) then return TRUE if p is the right endpoint of a segments then if both ABOVET, s) and BELOW (T, s) exist and ABOVET, ) intersects BELOW(Ts) then return TRUE DELETE(T, ) 12 return FALSE Time complexity: Line 2 takes O(nlg n) time. The for-loop has

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!