Question: Binary tree. Write one method in Java. My code seems to be wrong. So the task is: A binary tree is lucky if it contains
Binary tree. Write one method in Java. My code seems to be wrong. So the task is:
A binary tree is "lucky" if it contains at least 3 occurrences of some value. Make a method called luckyTree that checks to see if the given value occurs at least three times. If the tree is "lucky", return true; otherwise, return false.
So one method should be the main one, where the recursion occurs. Helper method should be implemented. Here is my sample code, can you please correct it? Should be easy.
public boolean luckyTree(int value) { // *FILL IN } if (root == null) { } return false; int k = luckyTree(root, value); return (k>=3); private int luckyTree (IntNode node, int value) { } int k = 0; if (node == null) { } return 0; if (node.data == value) { K++; } else { } luckyTree (node. left, value); luckyTree(node.right, value); return k;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
