Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

Define broadbanding. What is the purpose of using broadbanding?

Answered: 1 week ago

Question

Distinguish between merit pay, bonus, spot bonuses, and piecework.

Answered: 1 week ago