Write a method that finds depth of a (non-balanced) binary tree.
Sigiloso
Want an elegant solution? Here it goes. class Node { Node left; Node right; // other data members relevant to node, e.g. element. // constructors, getter/setters, etc. } class BinaryTree { Node root; int height() { calcDepth(root); } } int calcDepth(Node N) { if (N == null) return 0; return Math.max(calcDepth(N.left)+1,calcDepth(N.right)+1); } calcDepth is the method that computes the depth (or height) of a tree.