Question: Write a recursive method isBinaryTree() that takes a Node as an argument and returns true if the subtree count field N is consistent in the

Write a recursive method isBinaryTree() that takes a Node as an argument and returns true if the subtree count field N is consistent in the data structure rooted at that node, false otherwise.

This is my code.

Write a recursive method isBinaryTree() that takes a Node as an argument

This is the test. My code failed at the highlighted code.

and returns true if the subtree count field N is consistent in

This is the additional code that showed the resource code of updateN()

the data structure rooted at that node, false otherwise. This is my

How do do this problem?

public class Node , Value> Key key; // key Value val; // associated value NodeKey, Value> left, right; // links to subtrees static int lastvalue = Integer.MIN.VALUE; in n; // # nodes in subtree rooted here public Node (Key key, Value val, int n) this.keykey; this.val-val; k 3 @param node root of the sub-tree @return true if for each node in the sub-tree, n field value matches the number of nodes in its sub-tree, otherwise false public static boolean isBinaryTree(Node node) { return isBST (node, null, null); public static , Value boolean isBST (Node node, Key low, Key high) if (nodenul1) ( return true; if (lownull && low.compareTo(node.key) ) return false if (high != null && high . compareTo(node . key) 0) { return Talse return isBST (node.left, low, node.key) && isBST(node.right, node.key, high); public class Node , Value> Key key; // key Value val; // associated value NodeKey, Value> left, right; // links to subtrees static int lastvalue = Integer.MIN.VALUE; in n; // # nodes in subtree rooted here public Node (Key key, Value val, int n) this.keykey; this.val-val; k 3 @param node root of the sub-tree @return true if for each node in the sub-tree, n field value matches the number of nodes in its sub-tree, otherwise false public static boolean isBinaryTree(Node node) { return isBST (node, null, null); public static , Value boolean isBST (Node node, Key low, Key high) if (nodenul1) ( return true; if (lownull && low.compareTo(node.key) ) return false if (high != null && high . compareTo(node . key) 0) { return Talse return isBST (node.left, low, node.key) && isBST(node.right, node.key, high)

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 Databases Questions!