Question: 1 . The tree below is introduced in lecture 6 to demonstrate how to find max ( To find max or the second, we do
The tree below is introduced in lecture to demonstrate how to find max To find max or the second, we do not need to store the tree. The idea for finding second cannot be used to find the third. Why?
We can build this tree and use it to implement selection sort in a better way.
Implement the constructor, which builds a maximum tree out of an array.
Implement the deleteMax method, which removes the maximum element from the tree.
Implement the treeSort method to use this tree to do selection sort. Hint: please make sure you understand the tree before starting. During the execution, the leaves are precisely the set of unprocessed elements
very IMPORTANT: Do not change anything in Node class!!!
package compa;
import java.util.Arrays;
public class MaxTreedGigiYimMingHay Please change!
No modification to the class @code Node is allowed.
private class Node
int element;
public Node leftChild, rightChild;
public Nodeint element this.element element;
public String toString return String.valueOfelement;
Node root;
The constructor: Build a maximum tree out of an array.
VERY IMPORTANT.
I've sought help from the following Internet resources and books:
Running time: O
public MaxTreedGigiYimMingHayint a
Remove the root from a maximum tree and return its element.
I've sought help from the following Internet resources and books:
Running time: O
public int removeMax
The smart selection sort.
VERY IMPORTANT.
I've sought help from the following Internet resources and books:
Running time: O; space use: O
public static void treeSortint a
Todo: add at least ten more test cases to test your code.
The use of data structures from Java libraries is allowed here and only here.
public static void mainString args
int testData try different inputs.
;
for int a:testData
System.out.printlnThe original array: Arrays.toStringa;
treeSorta;
System.out.printlnSorted: Arrays.toStringa;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
