# Copy of Topic 08 Binary Trees Solutions.pdf - Solutions...

• Homework Help
• 3

This preview shows page 1 - 2 out of 3 pages.

Solutions - Topic 8, Recurrence Relations Copyright (c) 2016-2018 Dan Suthers. All rights reserved. These solution notes may ONLY be used by students in ICS 311 Fall 2018 at the University of Hawaii. Useful facts: a binary tree of height 0 consists of exactly one node, the root node. We can also consider “null” to be an empty tree of 0 nodes and undefined height. 1. Write a recursive procedure that counts and returns the number of nodes in a binary tree. countNodes (TreeNode root) 1 if root == null 2 return 0 3 else 4 return 1 + countNodes(root.left) + countNodes(root.right) 2. Prove this lemma, following the steps below. Lemma 1: The number of leaves in a complete binary tree of height h is 2 h . a. Base case: Show that Lemma 1 is true for h=0. When h=0, the formula predicts 2 0 = 1, which is the number of leaves in a tree of a single node (which has height 0). b. Induction: Assume that Lemma 1 is true for any complete binary tree of height h-1. Use this to show that the number of leaves in a complete binary tree of height h is 2 h .

#### You've reached the end of your free preview.

Want to read all 3 pages?

• Fall '08
• Barjaktarovic,M

### What students are saying

• 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.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern