sol10 - Massachusetts Institute of Technology Handout 23...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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 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 withof the query rectangle....
View Full Document

This note was uploaded on 11/24/2009 for the course CS 6.854/18.4 taught by Professor Davidkarger during the Fall '09 term at MIT.

Page1 / 4

sol10 - Massachusetts Institute of Technology Handout 23...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online