This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: EECS 310, Fall 2011 Instructor: Nicole Immorlica Problem Set #7 Due: November 15, 2011 1. (20 points) A kary tree is a tree in which each internal node has at most k children. The height h of a node is the length of the path from the root to the node. The height H of a tree is the maximum height of any node. (a) (10 points) Derive a formula for the maximum number of nodes of height h in a kary tree. Prove that your formula is correct using induction. Solution: We will show that the maximun number of nodes is of height h is k h . Induction Base: The only node with h = 0 is the root and Induction Hypothesis: Assume that the maximum number of nodes of height h is k h . Induction Step: We will show that the maximum number ofnodes of height h + 1 is k h +1 . Note that a node has height h if and only if it is the child of a node of height h . This is because the path that connects it to the root is the edge between the node and its parent node followed by the path that connects the parent to the root. Hence, the number of nodes of height h +1 is equal to the number of the children of nodes of height h . By the induction hypothesis the maximum number of nodes of height h is k h . The maximum number of children of each node is k . As a result, the maximum number of nodes of height h + 1 is k · k h = k h +1 , which proves the induction step. (b) (10 points) Using the above, write a summation to compute the maximum number of nodes in a ternary tree of height at most H and compute the closed form. Solution: For k = 3, there are 3 h nodes of height h . The maximum number of nodes is given by n = H X h =0 3 h (1) This is a geometric series (as learned in class) and the closed form gives us 1 3 H +1 1 3 2. (20 points) Consider an n × n grid. (a) (5 points) How many squares does the grid contain? For here, you do not give to a true closedform solutions, your solution may include summations (it probably should). Solution: A square on the grid is uniquely defined by its size and the location of one of its corners, wlog the upper left corner. Note that if a square has size k in order to fit in the grid, the maximym coordinates that its upper left corner can have is ( n k + 1 ,n k + 1). Also point with coordinates less than the previous bound defines a valid square. Hence, the squares of size k are equal to ( n k + 1) 2 . Summing over all possible square sizes, i.e., 1 through n we get the following formula n X i =1 ( n k + 1) 2 = n X i =1 k 2 (b) (5 points) How many rectangles does the grid contain?...
View
Full
Document
This note was uploaded on 01/15/2012 for the course ECON 101 taught by Professor N/a during the Fall '11 term at Middlesex CC.
 Fall '11
 N/A
 Economics

Click to edit the document details