Specify, design, and implement a class for binary trees where the nodes elements are stored in an
Question:
Specify, design, and implement a class for binary trees where the node’s elements are stored in an array, similar to the way that a complete binary tree is usually stored. However, these binary trees do not need to be complete. Instead, you should have a second private instance variable that is an array of boolean values called isPresent. The isPresent array indicates which nodes actually exist in the tree. For example, if the tree has a root node, then isPresent[0] is true. If the root has a left child, then isPresent[1] is true. If the root has a right child, then isPresent[2] is true, and so on.
The class should have methods to create the first node and to move a cursor around the tree. After the first node, new nodes may be added only as children of the cursor.
Step by Step Answer:
public class BinaryTree private int elements private boolean isPresent private int cursor public Bin...View the full answer
Students also viewed these Computer science questions
-
In this project, you will design and implement a class called Towers, which is part of a program that lets a child play a game called Towers of Hanoi. The game consists of three pegs and a collection...
-
This project uses the Towers class from Chapter 3s Programming Project 12. For the project, write a recursive methodxtxhxat computes and prints a solution to the Towers of Hanoi game. The method...
-
Specify, design, and implement a class for complete binary trees using the array representation from Section 9.2. You should have only one method that adds a new node (since there is only one place...
-
Using the aggregate expenditures table below, answer the questions that follow. a. Compute the APC when income equals $2,300 and the APS when income equals $2,800. b. Compute the MPC and MPS. c. What...
-
Using a collection of sample data, we construct a frequency table with 10 classes and then construct the corresponding histogram. How is the histogram affected if the number of classes is doubled but...
-
How will our ideas about privacy have to change if legions of super fast computers are analyzing the electronic records of our lives?
-
0.7357 Use the Standard Normal Table or technology to find the z-score that corresponds to the cumulative area or percentile. Table 4-Standard Normal Distribution Arca Z 0 Z .09 .08 .07 .06 .05 .04...
-
Consider a pressure surge system to reduce the effect of pressure variations at a compressor outlet on the pressure in a compressed gas header. We want to develop a two-tank model and evaluate the...
-
Explains your interest in the field of psychology and why developmental psychology is so important when working with drug and alcohol clients. , and what you ultimately hope to achieve in using...
-
The volume flow Q over a dam is proportional to dam width B and also varies with gravity g and excess water height H upstream, as shown in Fig. P1.14. What is the only possible dimensionally...
-
This project deals with a simple kind of expression tree, in which there are two kinds of nodes: (a) Leaf nodes, which contain a real number as their element; (b) Non-leaf nodes, which contain either...
-
Revise the animal-guessing program from Figure 9.8 so that the initial knowledge tree is obtained by reading information from a file. Also, when the program ends, the knowledge tree at that point is...
-
Find the area under the standard normal curve between z = -1.83 and z = 1.23, P(-1.83 < z < 1.23).
-
Is a count-controlled loop going from 1 through 5. At each iteration, the loop counter is either printed or put on a stack depending on the result of the Boolean function RanFun(). (The behavior of...
-
The following output (from \(\mathrm{R}\) ) presents the results of a hypothesis test for the difference \(\mu_{X}-\mu_{Y}\) between two population means: a. Is this a one-tailed or a two-tailed...
-
Is a count-controlled loop going from 1 through 5. At each iteration, the loop counter is either printed or put on a stack depending on the result of the Boolean function RanFun(). (The behavior of...
-
True or False? Both void and value-returning functions can be recursive.
-
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue (rear), a data member indicating the index of the location...
-
Five years ago Gerald invested $150,000 in a passive activity, his sole investment venture. On January 1, 2015, his amount at risk in the activity was $30,000. His shares of the income and losses...
-
When an electric field is applied to a shallow bath of vegetable oil, why do tiny bits of thread floating in the oil align with the field like compasses in a magnetic field?
-
Calculate the time necessary to perform a multiply using the approach described in the text (31 adders stacked vertically) if an integer is 8 bits wide and an adder takes 4 time units.
-
Calculate the time necessary to perform a multiply using the approach given in Figure 3.7 if an integer is 8 bits wide and an adder takes 4 time units. Figure 3.7 Mplier31 Mcand Mplier30 Mcand...
-
As discussed in the text, one possible performance enhancement is to do a shift and add instead of an actual multiplication. Since 9 6, for example, can be written (2 2 2 + 1) 6, we can calculate...
-
I need to find out how to calculate the 3-year % rate of return. The information I have is a $10,000 investment and a 12-month yield percentage (1.138 for AB company, 1.894 for AIG company, 0.679 for...
-
Anna has an investment that will bring her $100 with a 30% probability and $40 with a 70% probability. Anna's Utility function is U = Y (1/2) . Where Y= income. Anna is considering selling this...
-
on January 1, 2000, the price of koka kola was $10. on jan and, 2020, the shares were worth $100. the stock Paid no dividends during the period. what is the annual geometric return.
Study smarter with the SolutionInn App