Question: CODE IN JAVA PLEASE code listing for constructRandom: public void constructRandom(int n) { if(!isEmpty()) return; AtomicInteger key = new AtomicInteger(0); root = randomTree(null, n, key);
CODE IN JAVA PLEASE

code listing for constructRandom:
public void constructRandom(int n) { if(!isEmpty()) return; AtomicInteger key = new AtomicInteger(0); root = randomTree(null, n, key); }
private NoderandomTree(Node parent, Integer n, AtomicInteger key) {
if (n == 0) return null;
Integer leftCount = rnd.nextInt(n); // split the number of nodes Nodenode = new Node ((E)((Integer) key.get()), parent, null, null); size++;
key.getAndIncrement(); node.left = randomTree(node, leftCount, key);
key.getAndIncrement(); node.right = randomTree(node, n - leftCount - 1, key); return node;
}
// example usage
public static void main(String [] args) { Random rnd = new Random(); rnd.setSeed(42); LinkedBinaryTree bt = new LinkedBinaryTree(); bt.constructRandom(30); System.out.println(bt.toBinaryTreeString()); }
The split method for generating random binary trees splits the number of nodes n uniformly and assigns the number in the left split to the left child and the number in the right split to the right child. The process continues until all the nodes are used. The code for the constructRandom (int n ) method is below. Use this function to create random binary trees of the following sizes: N=[10,50,100,200,500,1000,2000,5000,10000,50000] For each size of tree, compute the average height and average diameter. You should find the average by generating 500 different random trees at each size. You should seed the random number generator with your student number: public static void main(String [] args) \{ Random rnd = new Random (); rnd.setSeed (2021..);// your student number (a) Your submission should include a table (b) Make a plot of the average height and diameter against N. (c) Using the trendline or fitting methods in your spreadsheet, find the Big-Oh complexity of the average height and average diameter with N
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
