I would like to calculate the summation of the depths of each node of a Binary Search Tree.
The individual depths of the elements are not already stored.
This solution is even more simpler.
public int getHeight(Node root) { if(root!=null) return 1+ Math.max(getHeight(root.leftchild),getHeight(root.rightchild)); else return 0; }