ps6sol - Introduction to Algorithms Massachusetts Institute...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Algorithms Day 23 Massachusetts Institute of Technology 6.046J/18.410J Singapore-MIT Alliance SMA5503 Professors Erik Demaine, Lee Wee Sun, and Charles E. Leiserson Handout 24 Problem Set 6 Solutions Exercise 6-1. Do exercise 14.1-5 on page 307 of CLRS. Solution: First find the rank of x . Add i to this value, and find the element with this rank. This takes 2 O (lg n ) + 1 time. Exercise 6-2. Do exercise 14.2-2 on page 310 of CLRS. Solution: Yes, since the black height of a node can be computed from the information at the node and its two children. According to Theorem 14.1 (page 309 of CLRS) insertion and deletion can be still performed in O (lg n ) time. Exercise 6-3. Do exercise 14.3-1 on page 316 of CLRS. Solution: Assume that before the rotation x has α as its left child and y as its right child, and y has β as its left child and γ as its right child. The rotation changes the pointers as in the L EFT -R OTATE procedure as shown on page 278 of CLRS. In addition, at the end it sets max [ y ] max [ x ] and max [ x ] max( max [ α ] , max [ β ] , high [ int [ x ]]) in that order. This takes O (1) time. Exercise 6-4. Do exercise 33.1-4 on page 946 of CLRS. Solution: For each point, sort the others by their polar angle relative to that point, and check if any two adjacent points in the sorted order have the same angle. For each point, we need O ( n ) time to compute the polar angles of all the other points, O ( n lg n ) time to sort them and O ( n ) time to check whether any two adjacent points have the same angle. We repeat the process for O ( n ) points, which gives us a total running time of O ( n 2 lg n ) . Exercise 6-5. Do exercise 33.2-1 on page 946 of CLRS. Solution: We can show this by construction: consider a regular polygon with n sides. If n is even, for each side of the polygon there is exactly one other side parallel to it (think of a square, or a hexagon). If n is odd, there are no parallel sides (think of a triangle or a pentagon). In any case, of all pairwise n ( n 1) / 2 combinations of sides, there are at most n/ 2 pairs of sides which are parallel to each other. The remaining n ( n 1) / 2 n/ 2 are not parallel. So if we extend them sufficiently in both directions, at some point they will intersect (pairwise). Thus we will have n segments with n ( n 1) / 2 n/ 2 = Θ( n 2 ) intersections. Problem 6-1. Overlapping rectangles VLSI databases commonly represent an integrated circuit as a collection of rectangles. Assume that each rectangle is rectilinearly oriented (sides parallel to the x - and y -axis), so that a representation of a rectangle consists of its minimum and maximum x - and y -coordinates.
Image of page 1

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

View Full Document Right Arrow Icon
2 Handout 24: Problem Set 6 Solutions (a) Give an O ( n lg n ) -time algorithm that decides whether a set of rectangles so repre- sented contains two rectangles that overlap. Your algorithm need not report all inter- secting pairs, but it must report that an overlap exists if one rectangle entirely covers another, even if the boundary lines do not intersect. ( Hint: Move a “sweep” line across the set of rectangles by replacing one of the two spatial dimensions with time. At all times maintain the collection of rectangles pierced by the sweep line.)
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern