{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

pset7soln - EECS 310 Fall 2011 Instructor Nicole Immorlica...

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

View Full Document Right Arrow Icon
EECS 310, Fall 2011 Instructor: Nicole Immorlica Problem Set #7 Due: November 15, 2011 1. (20 points) A k -ary 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 k -ary 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.
Image of page 1

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

View Full Document Right Arrow Icon
(a) (5 points) How many squares does the grid contain? For here, you do not give to a true closed-form 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? Solution: A rectangle is defined by the starting and ending x coordinates and starting and ending y coordinates. There are ( n 2 ) ways to choose the x coor- dinates and ( n 2 ) ways to choose the y coordinates. Therefore, the number of rectangles is n 2 n 2 (c) (10 points) Suppose the grid is missing an ( ( n - k ) 2 × ( n - k ) 2
Image of page 2
Image of page 3
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