I have to build avl tree and find its average depth i.e. height/no.of nodes. I could not figure out any other way so i decided to enter manually height and node value and do simple math division to calculate depth but the result is inf. I don't even know what is it.
sample - int height=2
int node =3
float depth = height/node = inf ???????
height / node equals zero, you need to promote one of the variables to float: (float)height / node
The max height of the tree can be found via recursion:
1 2 3 4 5 6 7 8 9 10 11
if (!ptr) return 0;
int leftHeight = getHeight(ptr->left);
int rightHeight = getHeight(ptr->right);
int max = leftHeight > rightHeight ? leftHeight : rightHeight;
return max + 1;