9.5.2. Binary Tree Increment By One Exercise X295: Binary Tree Increment By One Exercise Write a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
9.5.2. Binary Tree Increment By One Exercise X295: Binary Tree Increment By One Exercise Write a recursive function that increments by one the value for every node in the binary tree pointed at by root, then returns the modified tree. Assume that nodes store integer values. Here are methods that you can use on the BinNode objects: interface BinNode { public int value(); public void setValue(int v); public BinNode left(); public BinNode right(); } public boolean isLeaf(); Your Answer: 1 public BinNode BTinc (BinNode root) 2 { 4} Check my answer! Reset Feedback Your feedback will appear here when you check your answer. X466: Sorting - Fix Selection Sort The following method is a Selection Sort method. Within the method, there is an error on one line. You job is to find that line and fix that one error so that the method may work properly. You will need to understand exactly how a selection sort method works. Examples: selectionSort({4,7,1}) -> {1,4,7} selectionSort({80,6,6,8,2}) -> {2,6,6,8,80} Your Answer: Feedback Your feedback will appear here when you check your answer. 1 public int[] selectionSort(int[] array) { 2 3 for (int i = 0; i < array.length - 1; i++) { int min = array[i]; 4 int minIndex = i; 5 6 7 8 for (int j = i + 1; j < array.length; j++) { if (min > array[j]) { min = array[j]; minIndex = j; 9 } 10 } 11 if (minIndex 12 13 == array[minIndex] array[i] = min; i) { array[i]; 14 } 15 } 16 17 } return array; 18 Check my answer! Reset Next exercise X488: Sorting - Quick Sort Write a method quicksort that takes in an ArrayList of integers and returns them in ascending order, using a quicksort style of sorting. Remember that this style relies on choosing a pivot integer and breaking the set into values less than the pivot and more than the pivot, then repeating this process on each half until only single values are left, which are then put back together. Your Answer: 1 public ArrayList<Integer> quickSort(ArrayList<Integer> list) { Feedback Your feedback will appear here when you check your answer. 2 3} Check my answer! Reset Next exercise 9.5.2. Binary Tree Increment By One Exercise X295: Binary Tree Increment By One Exercise Write a recursive function that increments by one the value for every node in the binary tree pointed at by root, then returns the modified tree. Assume that nodes store integer values. Here are methods that you can use on the BinNode objects: interface BinNode { public int value(); public void setValue(int v); public BinNode left(); public BinNode right(); } public boolean isLeaf(); Your Answer: 1 public BinNode BTinc (BinNode root) 2 { 4} Check my answer! Reset Feedback Your feedback will appear here when you check your answer. X466: Sorting - Fix Selection Sort The following method is a Selection Sort method. Within the method, there is an error on one line. You job is to find that line and fix that one error so that the method may work properly. You will need to understand exactly how a selection sort method works. Examples: selectionSort({4,7,1}) -> {1,4,7} selectionSort({80,6,6,8,2}) -> {2,6,6,8,80} Your Answer: Feedback Your feedback will appear here when you check your answer. 1 public int[] selectionSort(int[] array) { 2 3 for (int i = 0; i < array.length - 1; i++) { int min = array[i]; 4 int minIndex = i; 5 6 7 8 for (int j = i + 1; j < array.length; j++) { if (min > array[j]) { min = array[j]; minIndex = j; 9 } 10 } 11 if (minIndex 12 13 == array[minIndex] array[i] = min; i) { array[i]; 14 } 15 } 16 17 } return array; 18 Check my answer! Reset Next exercise X488: Sorting - Quick Sort Write a method quicksort that takes in an ArrayList of integers and returns them in ascending order, using a quicksort style of sorting. Remember that this style relies on choosing a pivot integer and breaking the set into values less than the pivot and more than the pivot, then repeating this process on each half until only single values are left, which are then put back together. Your Answer: 1 public ArrayList<Integer> quickSort(ArrayList<Integer> list) { Feedback Your feedback will appear here when you check your answer. 2 3} Check my answer! Reset Next exercise
Expert Answer:
Answer rating: 100% (QA)
depicts a prompt for a coding exercise about binary trees The goal is to write a recursive function that increases the value of each node in a binary tree by one Heres a possible solution Java public ... View the full answer
Related Book For
Practical Introduction To Data Structures And Algorithm Analysis Java Edition
ISBN: 9780136609117
1st Edition
Authors: Clifford A. Shaffer
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
see below questions and provide me adjusted coding by using my coding. I share my coding and test failure message at the end. 1. BST.java 2.BSTNode.java Binary Search Tree you will be coding the...
-
In its first year of operation, Oriole Printing Shop estimated manufacturing overhead costs and activity in order to determine a predetermined overhead rate. At year end, March 31, overhead was...
-
You serve as the trustee for the Sooner XXV trust. The following transactions occur during 2015: September 15 Open the Sooner XXV trust account, depositing the $100,000 transferred from the estate of...
-
A three-phase, variable-speed induction motor is operated from a variable frequency, variable-voltage source which is controlled to maintain constant peak air-gap flux density as the frequency of the...
-
What is the amount of net new financing needed for Jims?
-
A thin-walled tube of 20-mm diameter passes hot fluid at a mean temperature of 45C in an experimental flow loop. The tube is mounted horizontally in quiescent air at a temperature of 15C. To satisfy...
-
A wheel of 100 cm diameter, 1000 N weight is resting against a block of 25 cm height. Find minimum force P at angle 45 with horizontal when the wheel is just on the point of climbing the block. P...
-
A partially completed worksheet for At Home Pet Grooming Service, a firm that grooms pets at the owner's home, follows. INSTRUCTIONS 1. Record balances as of December 31 in the ledger accounts. 2....
-
3. Differentiators, Value Proposition and Other Features Describe the three features or attributes of your Tesla product that differentiate it from its competitors and substitutes. Describe briefly...
-
You just won the lottery. You have chosen the annuity option which gives you a total of 16 annual cash payments of $5,000 each, with the first payment being made one year from today. You decide to...
-
Gale is separated from her husband two months ago. The relationship between Gale and her husband is hostile. He is trying to gain custody of their two childrena boy of eight and a girl of five years....
-
An object has a position given by T 2.00 s? = [2.0 m (5.00 m/s)t] + [3.0m (3.00 m/s)+2], where quantities are in SI units. What is the speed of the object at time t =
-
1. The bond of Nichols Corp is currently trading at (the price of a bond) $700.00. The bond matures in 20 years and has today a yield to maturity of 3%. This is a semiannual coupon bond with a par...
-
NCell- Financial Data Collection In this assignment you will collect data that are available for valuation of NCell. Specify the sources and check the reliability of data being collected. Some of the...
-
Find the values of the double integrals. Write the integral you are calculating (2xy + y^3) dA Where R ={-1 x 2, 0 y 2}
-
For the following exercises, rewrite the sum as a product of two functions or the product as a sum of two functions. Give your answer in terms of sines and cosines. Then evaluate the final answer...
-
Write out a table showing the number of comparisons required to find the minimum and maximum for all divisions for all values of \(n \leq 13\).
-
Define an ADT for a bag of integers (remember that a bag may contain duplicates, and has no concept of order). Your ADT should consist of the functions that can be performed on a bag to control its...
-
Imagine that you have been hired to design a database service containing information about cities and towns in the United States, as described in Example 1.2. Suggest two possible implementations for...
-
In the second quarter of 2021, personal consumption expenditures, exports, and imports increased. Investment and government expenditure decreased. Real GDP increased by 6.5 percent following a 6.3...
-
When real GDP increased in the second quarter of 2021, consumption expenditure, exports, and imports increased. Fixed investment decreased, which included a decrease in business inventory investment....
-
Explain for each event whether it changes short-run aggregate supply, long-run aggregate supply, aggregate demand, or some combination of them. The following events have occurred at times in the...
Study smarter with the SolutionInn App