ALGORITHM LeafCounter(BTNode node)
// Computers recursively the number of leaves in a binary tree
// Input: Root node of a binary (sub-)tree 1/
// Output: The number of leaves in the tree rooted by input node
if (node == null) return 0;
else
return LeafCounter(node.getLeftChild 0 ) + Leaf Counter(node.getRightChild();
I am not sure how to edit this so it will accurately count leaves? Also, if you could supply proof of why this fails it would be very helpful as to me, it looks like it should be working
Correct Algorithm:
Note:You may need to subtract 1 from final result, to exclude the root node from count.