Given the following class representing a node in a binary tree, answer the following questions: public...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given the following class representing a node in a binary tree, answer the following questions: public class BinaryNode<E> { public E element;//data public BinaryNode<E> left://left child public BinaryNode<E> right://right child public BinaryNode(E element){ this(element, null, null); 1 public BinaryNode(E element, BinaryNode<E> left. BinaryNode<E> right) this left-left: this.right-right: this.element element; 1 a. (10 points) Write a few lines of Java code that constructs an object of BinaryNode<Integer> (called root) which represents the root of a binary tree with the following features: • tree's root has an element equal to 5, and has two children • root's left child has an element equal to 3 and has two children with elements 2 and 6 (left child contains 2 and right child contains 6) . • root's right child has an element equal to 7 and a single child on the right with element 10 . • Tree has only 6 nodes b. (5 points) is the binary tree defined in previous part considered to be a Binary Search Tree? Briefly justify your answer. c. (5 points) What is the height of the tree defined in part a? Briefly justify your answer. d. (5 points) is the tree defined in previous part balanced? Briefly justify your answer. e. (9 points) Write down the pre-order, In-order and post-order traversal of the tree defined in part a Given the following class representing a node in a binary tree, answer the following questions: public class BinaryNode<E> { public E element;//data public BinaryNode<E> left://left child public BinaryNode<E> right://right child public BinaryNode(E element){ this(element, null, null); 1 public BinaryNode(E element, BinaryNode<E> left. BinaryNode<E> right) this left-left: this.right-right: this.element element; 1 a. (10 points) Write a few lines of Java code that constructs an object of BinaryNode<Integer> (called root) which represents the root of a binary tree with the following features: • tree's root has an element equal to 5, and has two children • root's left child has an element equal to 3 and has two children with elements 2 and 6 (left child contains 2 and right child contains 6) . • root's right child has an element equal to 7 and a single child on the right with element 10 . • Tree has only 6 nodes b. (5 points) is the binary tree defined in previous part considered to be a Binary Search Tree? Briefly justify your answer. c. (5 points) What is the height of the tree defined in part a? Briefly justify your answer. d. (5 points) is the tree defined in previous part balanced? Briefly justify your answer. e. (9 points) Write down the pre-order, In-order and post-order traversal of the tree defined in part a
Expert Answer:
Answer rating: 100% (QA)
java public class BinaryNode public E element data public BinaryNode left left child public BinaryNode right right child public BinaryNodeE element th... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Find the turning points on the curve y = 2x 3 5x 2 + 4x 1 and determine their nature. Find the point of inflection and sketch the graph of the curve.
-
Suppose you took random samples from three distinct age groups. Through a survey, you determined how many respondents from each age group preferred to get news from TV, newspapers, the Internet, or...
-
Express ln(xe x ) as the sum or difference of logarithms, evaluating where possible.
-
Petitioner Curtis Flowers has been tried six separate times for the murder of four employees of a Mississippi furniture store. Flowers is black; three of the four victims were white. At the first two...
-
The Henry Street Mission uses volunteers to assemble care packages for needy families during the holiday season. The mission would like to organize the work as efficiently as possible. A list of...
-
2. 2. A 20 kg child climbs to the top of a slide that is 3 m above the ground level. She starts from rest and slides down the incline. a. Define and model the energy of the system with Energy Bar...
-
Mary Janes Beauty Shop has recently invested money to add more equipment to enable more services to be offered at the shop. Given the following information evaluate their investment.
-
On R2 add vectors as usual, but multiply them by the formula (a, b) (c,d) = (ac, bd). Does R2 with this addition and multiplication form a field? (HINT: when can you divide?)
-
A solution contains 14 milliliters of alcohol and 32 milliliters of water. If another solution is to have the same concentration of alcohol in water but is to contain 56 milliliters of water, how...
-
Determine lim x 1 x 4-1 x-1
-
To complete this journal assignment, first you should listen and watch this speech closely because you will be discussing the speech's rhetorical context. "What Streaming Means for the Future of...
-
Quality of financial reporting, Management of expenses and revenue in Australian Healthcare Sysytem: 2.1 Explain the concepts of faithful representation and accrual basis accounting. Elaborate how...
-
A unixial compression test on a sandstone specimen is to be conducted under displacement-controlled condition. The specimen is 50mm in diameter and 100mm in height. The young's modulus of the...
-
Presented below is the partial bond discount amortization schedule for Oriole Corp. Oriole uses the effective-interest method of amortization. Interest Expense to Be Discount Amortization Unamortized...
-
Gopher, Inc. developing its upcoming budgeted Costs of Quality (COQ) with the following information: Expense Item Budget Raw Materials Inspection $ 15,000 EPA Fine 200,000 Design Engineering 15,000...
-
Incorporate the RGBA color chooser you created in the Color Chooser app into the Painter app so that the user can choose any drawing color. Changing a Sliders value should update the color swatch...
-
Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits...
-
Assuming that random is a SecureRandom object, explain in detail the stream pipeline: random.ints(1000000, 1, 3) .boxed() .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))...
-
Salen Company finances some of its current operations by assigning accounts receivable to a finance company. On July 1, 2015, it assigned, under guarantee, specific accounts amounting to 150,000,000....
-
Bill Jovi is reviewing the cash accounting for Nottleman, Inc., a local mailing service. Jovis review will focus on the petty cash account and the bank reconciliation for the month ended May 31,...
-
On October 1, 2015, Arden Farm Equipment Company sold a pecan-harvesting machine to Valco Brothers Farm, Inc. In lieu of a cash payment Valco Brothers Farm gave Arden a 2-year, $120,000, 8% note (a...
Study smarter with the SolutionInn App