I want to find the max depth of binary search tree. I found a code.
int maxDepth(struct node* node) {
if (node==NULL) {
return(0);
}
else {
// compute the depth of each subtree
int lDepth = maxDepth(node->left);
int rDepth = maxDepth(node->right);
// use the larger one
if (lDepth > rDepth) return(lDepth+1);
else return(rDepth+1);
}
}
I want to know that how come node->left would return 1 ?
Is it by default ? The code is easy but I do not know from where is the answer coming, can anyone explain me please ?