# hw1sol - CS 473 Homework 1(due February 2 2009 Spring 2010...

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

CS 473 Homework 1 (due February 2, 2009) Spring 2010 1. (a) How many cells are there, as a function of n ? Prove your answer is correct. Solution: A kd-tree is a binary tree, where each internal node corresponds to a cut through one of the points, and each leaf corresponds to a cell. A kd-tree for n points is a binary tree with n internal nodes and therefore has n + 1 leaves. We can also prove this fact by induction. A kd-tree for 0 points has a single cell: the entire plane. For any n > 0, a kd-tree for n points consists of a root node and two sub-kd-trees. Suppose the left subtree contains k points; then the right subtree contains n - k - 1 points. The induction hypothesis implies that the left subtree has k + 1 cells, and the right subtree has n - k cells. So the total number of cells is ( k + 1 )+( n - k ) = n + 1, as claimed. In both proofs, the fact that the tree is balanced is irrelevant! ± Rubric: 1 point max: ½ for answer ( n + 1 ) + ½ for proof. Only one proof is necessary; these are not the only correct proofs! (b) In the worst case, exactly how many cells can a horizontal line cross, as a function of n ? Prove your answer is correct. Assume that n = 2 k - 1 for some integer k . Solution: Let H ( n ) be the number of cells crossed by a horizontal line in a kd-tree for n points whose top-level cut is horizontal, and let V ( n ) be the number of cells crossed if the top-level cut is vertical. We have a pair of mutual recurrences H ( n ) = V ( b n / 2 c ) and V ( n ) = 2 H ( b n / 2 c ) , with base cases H ( 0 ) = V ( 0 ) = 1. we can combine these into a single recurrence V ( n ) = 2 V ( b n / 4 c ) , with base cases V ( 0 ) = 1 and V ( 1 ) = 2. The related function v ( k ) = lg V ( 2 k - 1 ) satisﬁes the even simpler recurrence v ( k ) = v ( k - 2 )+ 1 with base cases v ( 0 ) = 0 and v ( 1 ) = 1. The solution v ( k ) = d k / 2 e now follows by a one-line induction proof, which implies that V ( 2 k - 1 ) = 2 d k / 2 e . Rewriting in terms of n , we ﬁnd that V ( n ) = p n + 1 if k is even, and V ( n ) = p 2 ( n + 1 ) if k is odd. ± Rubric: 2 points max: 1 point for answer and 1 point for proof. - ½ if the answer is not given as a function of n , or is not simpliﬁed. This is not the only correct proof! (c) Suppose we have n points stored in a kd-tree. Describe and analyze an algorithm that counts the number of points above a horizontal line (such as the dashed line in the ﬁgure) as quickly as possible. [Hint: Use part (b).] Solution: We prepose the following recursive algorithm. The main idea is to recursively calculate the total number of points above the line in both subtrees, but we don’t recurse if all points in a subtree lie above the line, or all points in a subtree lie below the line. Each node

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/18/2011 for the course CS 473 taught by Professor Chekuri,c during the Spring '08 term at University of Illinois, Urbana Champaign.

### Page1 / 5

hw1sol - CS 473 Homework 1(due February 2 2009 Spring 2010...

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

View Full Document
Ask a homework question - tutors are online