For simplicity assume that no two horizontal segments

• Notes
• 2

This preview shows pages 1–2. Sign up to view the full content.

horizontal or vertical. For simplicity, assume that no two horizontal segments overlap, and no two vertical segments overlap. In lecture, we discuss an algorithm that computes and outputs all of the intersection points between segments in our set. The running time of this algorithm is output-sensitive — it runs in O ( n log n + P ) time, where P is the number of points output by the algorithm. In the worst case, its running time could be quadratic. Give an algorithm that counts the total number of intersection points in only O ( n log n ) time.

This preview has intentionally blurred sections. Sign up to view the full version.

2 Handout 20: Problem Set 7 Problem 7-3. Painting Rectangles When not solving algorithms problems, TA Mihai B˘adoiu enjoys painting pictures of over- lapping rectangles. For his latest project, he has chosen a set of n rectangles in the plane, each of which is specified by three numbers, given to you in arrays x 1 [1 . . . n ], x 2 [1 . . . n ], and y [1 . . . n ]. The corners of the i ’th rectangle will be ( x 1 [ i ] , 0), ( x 1 [ i ] , y [ i ]), ( x 2 [ i ] , y [ i ]), and ( x 2 [ i ] , 0). The rectangles may overlap each-other. Mihai is curious how much paint he will need to buy to color in all of the rectangles. Help him out by devising an algorithm that computes, in O ( n log n ) time, the area of the union of all n rectangles.
This is the end of the preview. Sign up to access the rest of the document.
• Spring '03
• PiotrIndyk
• Algorithms, Big O notation, Analysis of algorithms

{[ snackBarMessage ]}

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern