In last article we saw how can we print the binary tree using line by line that is level order traversal. In this article we will see how can we print the size of the binary tree.
So here in the image you can see we have a binary tree. You have to print the size of this binary tree.
In this image we can clearly see that the size of the tree is 6 because total number of nodes in this binary tree are 6 so our output must be 6.
So now we are going to implement a Java code for this problem.
Java Code :
Time Complexity : O(n)
Auxilary Space : O(h)