find the number of nodes in a binary tree greater than x
If you’re walking the tree from the root down, you don’t need to propagate ‘counts’ downward at all–the fact that you are is resulting in repeated counting of nodes as they contribute to both count, countLeft, and countRight, since you increment count before passing it to nodesGreaterThanX for the children. public static int nodesGreaterThanX(BinaryTreeNode<Integer> node, … Read more