Question: The attached code provides a program related to binary trees. Analyze the code to determine what it does. In a text box response, describe what

The attached code provides a program related to binary trees. Analyze the code to determine what it does. In a text box response, describe what the code does and write out both the trees that it creates.

Are "tree" and "tree2" both valid Binary Search Trees? Why is this code a poor way to build a binary tree?

class Node int data; Node left, right; public Node(int item) { data

class Node int data; Node left, right; public Node(int item) { data = item; left = right = null; } } public class binaryTree { Node root; int getNum() } return getNum(root); int getNum(Node node) { } if (node == null) return 0; if (node.left == null && node.right == null) return 1; else return getNum(node.left) + getNum(node.right); public static void main(String args[]) { binaryTree tree = new binaryTree(); tree.root = new Node(32); tree.root.left = new Node(17); tree.root.left.right = new Node(28); tree.root.right = new Node(37); tree.root.right.right = new Node(54); tree.root.left.right.left = new Node (21); tree.root.left.left = new Node (8); tree.root.right.right.left = new Node(40); tree.root.left.right.right = new Node(29); tree.root.left.left.right = new Node(13); System.out.println(tree.getNum()); binaryTree tree2 = new binaryTree(); tree2.root = new Node(11); tree2.root.right = new Node (24); tree2.root.left = new Node(9); tree2.root.right.left = new Node(27); tree2.root.right.right = new Node (32); tree2.root.left.left = new Node(2); System.out.println(tree2.getNum()); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!