Question: 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


9.5.2. Binary Tree Increment By One Exercise X295: Binary Tree Increment ByOne Exercise Write a recursive function that increments by one the valuefor every node in the binary tree pointed at by root, then

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 quickSort(ArrayList list) { Feedback Your feedback will appear here when you check your answer. 2 3} Check my answer! Reset Next exercise

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

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 full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!