sol10 - Massachusetts Institute of Technology...

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

View Full Document Right Arrow Icon
Massachusetts Institute of Technology Handout 23 6.854J/18.415J: Advanced Algorithms Monday, November 23, 2009 David Karger Problem Set 10 Solutions Monday, November 23, 2009 Collaboration policy: collaboration is strongly encouraged . However, remember that 1. You must write up your own solutions, independently. 2. You must record the name of every collaborator. 3. You must actually participate in solving all the problems. This is difficult in very large groups, so you should keep your collaboration groups limited to 3 or 4 people in a given week. 4. No bibles. This includes solutions posted to problems in previous years. Problem 1. Consider the problem of finding all (horizontal and vertical) segments that intersect a query rectangle Q = < X 1 , Y 1 , X 2 , Y 2 > . A solution can be expressed as the set of all horizontal line segments that intersect the vertical line through X 1 or X 2 and lie between Y 1 and Y 2 on the vertical axis, and the corresponding set of vertical line segments (replacing “horizontal” with “vertical” and vice versa above). We give the procedure for identifying the intersecting horizontal line segments (the former case); the latter case is precisely symmetric. Consider a horizontal segment s i . It is defined by its left and right endpoints x i and x 0 i and its y coordinate, y i . Our problem is to find all s i such that Y 1 y i Y 2 and the interval [ x i , x 0 i ] contains X 1 or X 2 . To accomplish this, we create a data structure made up of a primary balanced BST ordered by y i (as in range search), and associate with each internal node an interval tree of the x -coordinate intervals of the line segments in that node’s subtree. The space required for the primary tree is O ( n ). It is a balanced tree, so each node has O (log n ) ancestors. Each segment has a representation in each of the interval trees corre- sponding to its ancestors in the primary search tree, and there are n segments, so the space required for the interval trees is O ( n log n ). Once we have built this data structure, we can perform queries for a given query rectangle by walking through the primary tree and querying all the interval trees corresponding to nodes between the top and bottom coordinates Y 1 and Y 2 of the query rectangle. As with range search, the size of the set S
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
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