Question: Write a method called countEmpty that returns the number of empty branches in a tree. An empty tree is considered to have one empty branch

Write a method called countEmpty that returns the number of empty branches in a tree. An empty tree is considered to have one empty branch (the tree itself). For nonempty trees, your methods should count the total number of empty branches among the nodes of the tree. A leaf node has two empty branches, a node with one nonempty child has one empty branch, and a node with two nonempty children has no empty branches. For example, reference tree #1 has 7 empty branches (two under the value 1, one under 5, and two under each of 4 and 6).

Reference Tree #2 2 Reference Tree #1 1 7. 4 4 Reference Tree #3 2 3 8. 9. 3. 1.

Reference Tree #2 2 Reference Tree #1 1 7. 4 4 Reference Tree #3 2 3 8. 9. 3. 1.

Step by Step Solution

3.49 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public int countEmpty private int co... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!