Question: A binary tree is called perfect if all of its nodes have exactly 0 or 2 children and all of its leaves are at the

A binary tree is called perfect if all of its nodes have exactly 0 or 2 children and all of its leaves are at the same level. By the size of a perfect tree we mean its number of nodes.
Write a function:
Class solution{public int soultion(Tree T)};size of the biggest perfect subtree that can be obtained by removing nodes. For example, given tree T as shown in the previous figure, the funct i should return 7, as explained above.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
the height of tree T (number of edges on the longest path from root to leaf) is within the range [0.800].
Technical details
A binary tree can be specified using a pointer data structure. Assume that the following declarations are given:
class Tree {
public int x;
public Tree l;
public Tree r;
}
An empty tree is represented by an empty pointer (denoted by null). A non-empty tree is represented by a pointer to an object representing its root. The attribute holds the integer contained in the root, whereas attributes 1 and r hold the left and right subtrees of the binary tree, respectively.
For the purpose of entering your own test cases, you can denote a tree recursively in the following way. An empty binary tree is denoted by None. A non-empty tree is denoted as (X, L, R), where X is the value contained in the root and L and R denote the left and right subtrees, respectively. The tree from the above figure can be denoted as:
(1,(2, None, (4, None, None)),(3,(5,(7, None, None),(8, None, None)),(6,(9, None, None),(10,(11, None, None),
None))))
Write java8 solution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!