Write a method called makePerfect that adds nodes until the binary tree is a perfect tree. A
Question:
Write a method called makePerfect that adds nodes until the binary tree is a perfect tree. A perfect binary tree is one where all leaves are at the same level. Another way of thinking of it is that you are adding dummy nodes to the tree until every path from the root to a leaf is the same length. A perfect tree’s shape is exactly triangular and every branch node has exactly two children, and all of the leaves are at the same level. Each new node you add to the tree should store the value 0 . For example, if a variable t refers to reference tree #2, then the call t.makePerfect(); should change the tree’s state to the following:
1 7 4 Reference Tree #2 2 Reference Tree #1 3 1. Reference Tree #3
Step by Step Answer:
public void makePerfect int heig...View the full answer
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Students also viewed these Computer science questions
-
Write a method called isFull that returns true if a binary tree is full and false if it is not. A full binary tree is one in which every node has 0 or 2 children. For example, reference trees #1 and...
-
Write a method called combineWith that accepts another binary tree of integers as a parameter and combines the two trees into a new third tree that is returned. The new trees structure should be a...
-
Write a method called countEvenBranches that returns the number of branch nodes in a binary tree that contain even numbers. A branch node has one or two children (i.e., it is not a leaf). For...
-
A long cylindrical wood log (k = 0.17 W/mK and = 1.28 10 -7 m 2 /s) is 10 cm in diameter and is initially at a uniform temperature of 15C. It is exposed to hot gases at 550C in a fireplace with a...
-
If, while standing on a bank, you wish to spear a fish beneath the water surface in front of you, should you aim above, below, or directly at the observed fish to make a direct hit? If, instead, you...
-
Identifytwosupertrendsor megatrends that you would recommend investing in for the next 20 to 40 years. There are no restrictions on the trends or asset classes that you select any from the ones we...
-
The following MINITAB output presents a 95% confidence interval for the mean ozone level on days when the relative humidity is 60%, and a 95% prediction interval for the ozone level on a particular...
-
On January 1, 2010, Allan acquires 15 percent of Bellevue's outstanding common stock for $62,000. Allan classifies the investment as an available-for-sale security and records any unrealized holding...
-
Suppose that the McDonalds in California is for sale. Its balance sheet as of 12/31/24 lists: (i) the property (i.e., the land and building) is $700,000, the equipment and furniture are $100,000, its...
-
The percent of college students marijuana use for a sample of 95,761 students is shown in the pie chart. Find the probability of each event. (a) Randomly selecting a student who never used marijuana....
-
Draw the binary search tree that would result if the given elements were added to an empty binary search tree in the given order. Then write the elements of the tree in the order that they would be...
-
Draw the binary search tree that would result if the given elements were added to an empty binary search tree in the given order. Then write the elements of the tree in the order that they would be...
-
Use integration to show that a sphere of radius r has volume V || 4 3 T 3
-
Read the following cases and then answer the questions below. Cases: Goddard v. Boston M.R. Co ., 60 N.E. 486 (Mass. 1901) Anjou v. Boston Elevated Ry. Co., 94 N.E. 386 (Mass. 1911) Mascary v. Boston...
-
Discuss 2 reasons why databases are essential for accounting information systems. Describe 2 concerns in using databases in AIS. Discuss what is meant by primary key and foreign key in databases. The...
-
A company offers three (3) products for sale: candies, ice-pops and sandwiches. The following information is available for the three products: Candies Ice-pops Sandwiches Selling price $25 $40 $80...
-
In order to manage working capital effectively, two competing goals-profitability and liquidity-must be balanced. A company is said to be overcapitalized if it has an excessive amount of working...
-
9. Write P(x) as a product of linear factors: P(x) = x+2x-5x-6; Use the fact that - 1 is a zero
-
A quantitative data set of size 60 has mean 100 and standard deviation 16. At least how many observations lie between 68 and 132? Apply Chebyshev's rule to solve.
-
Find the center of mass of a thin triangular plate bounded by the y-axis and the lines y = x and y = 2 - x if (x, y) = 6x + 3y + 3.
-
Using the statements you wrote in Exercise 3.5, write a complete app that calculates and displays the product of three integers. Data From Problem 3.5 Write declarations, statements or comments that...
-
What does the following code display? Console.Write("*"); Console.Write("***"); Console.Write("*****"); Console.Write("****"); Console.WriteLine("**");
-
What does the following code display? Console.Write("*"); Console.WriteLine("***"); Console.WriteLine("*****"); Console.Write("****"); Console.WriteLine("**");
-
4- Assume that printer interrupt priority: 2, disk interrupt priority:4, Ethernet interrupt priority: 5. A user program starts at t = 0 and takes 40 seconds to complete. At t = 10, a disk interrupt...
-
Robbie is a 3 year old boy in the bur oak room at little.ly early learning centre. You have been one of robbies educators for the past two weeks. You and your colleagues have been concerned about...
-
Write Matlab statements to perform the following operations. Store the values of x in an array X and use it to calculate y. Store the values of y in Y. For the function 4 sin x+6 y= calculate the...
Study smarter with the SolutionInn App