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.
private static int getNumberOfNodes(Node node) { if (node == null) { return 0; } return 1 + getNumberOfNodes(node.left) + getNumberOfNodes(node.right); }