Question: Can someone please check my recursive function below for mistakes? Thanks! Assignment: Write a function to find the sum of all the odd keys in

Can someone please check my recursive function below for mistakes? Thanks!

Assignment: Write a function to find the sum of all the odd keys in a Binary Search Tree.

public int numOddKeys(Node root) {

return numOddKeysHelper(root);

}

public int numOddKeysHelper(Node root) {

if(root == null) return 0;

int left = numOddKeysHelper(root.left);

int right = numOddKeysHelper(root.right);

if(root.data % 2 == 0) return left +right;

return (left + right + 1);

}

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!