0% found this document useful (0 votes)
79 views2 pages

6.851 Advanced Data Structures (Spring'12) Prof. Erik Demaine Problem 2 Sample Solution

This document discusses algorithms for constructing range trees in multiple dimensions. It states that if a (d-1)-dimensional range tree can be constructed in O(n logd-2 n) time, then a d-dimensional range tree can be constructed in O(n logd-1 n) time by recursively building lower-dimensional subtrees. It also explains that a 2-dimensional range tree can be built in O(n log n) time by first sorting by the y-coordinate and then efficiently building the tree over the x-coordinate values.

Uploaded by

djoseph_1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views2 pages

6.851 Advanced Data Structures (Spring'12) Prof. Erik Demaine Problem 2 Sample Solution

This document discusses algorithms for constructing range trees in multiple dimensions. It states that if a (d-1)-dimensional range tree can be constructed in O(n logd-2 n) time, then a d-dimensional range tree can be constructed in O(n logd-1 n) time by recursively building lower-dimensional subtrees. It also explains that a 2-dimensional range tree can be built in O(n log n) time by first sorting by the y-coordinate and then efficiently building the tree over the x-coordinate values.

Uploaded by

djoseph_1
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

6.851 Advanced Data Structures (Spring12) Prof.

Erik Demaine Problem 2


Range tree construction. 1. If we can construct a d 1-dimensional range tree in O(n lgd2 n) time, then we can easily construct a d-dimensional range tree in O(n lgd1 n) time. To do this, we construct the tree from the root down. First, construct a d 1 dimensional range tree over all elements for the root, then divide on the dth dimension and pass down the relevant elements to each subtree and recursively build them. The total running time is then T (n, d) = 2T (n/2, d) + T (n, d 1) = 2T (n/2, d) + O(n lgd2 n) which solves to O(n lgd1 n) by the Master theorem. All that remains then, is to show how to construct a 2-dimensional range tree in O(n lg n) time. To do this, rst sort the elements by y in O(n lg n) time. We then build the tree over x as before, except since the elements are sorted by y (which we can easily maintain as we work down the tree) the time to build each balanced tree over y is O(n), for a total of T (n, 2) = 2T (n/2, 2) + T (n, 1) = 2T (n/2, 2) + O(n) = O(n lg n). 2. The procedure for a constructing a layered range tree is identical to the previous section, except instead of building the tree over y in O(n) time, we must instead compute the pointers between adjacent layers in O(n) time. This can be done by with a merge-like operation on the child and parent arrays. Keep a pointer to the head of each array, if the y value at the child head is less than the y value at the parent head, then increment the child head. Otherwise, the parent head points to the child head and we increment the parent head.

Sample solution

MIT OpenCourseWare http://ocw.mit.edu

6.851 Advanced Data Structures


Spring 2012

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

You might also like