Write a function to find the depth of a binary tree.

Answer Posted / mohan p

int depth(treenode *p)
{
if(p==NULL)return(0);
if(p->left){h1=depth(p->left);}
if(p=>right){h2=depth(p->right);}
return(max(h1,h2)+1);
}

The above code will return the number of nodes in the
longest path from root to the leaf. So subtracting with -1
will give the depth of the tree. Depth of the tree is the
distance from root to the deepest leaf.

Is This Answer Correct ?    13 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3244


Develop a routine to reflect an object about an arbitrarily selected plane

3274


write a simple calculator c program to perform addition, subtraction, mul and div.

3384


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

4071


write a function to give demostrate the functionality of 3d in 1d. function prototye: change(int value,int indexX,int indexY,int indexZ, int [] 1dArray); value=what is the date; indexX=x-asix indexY=y-axis indexZ=z-axis and 1dArray=in which and where the value is stored??

4388






write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2436


how to test pierrot divisor

2457


could you please send the program code for multiplying sparse matrix in c????

3276


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2564


why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2497


How to palindrom string in c language?

9776


What is data _null_? ,Explain with code when u need to use it in data step programming ?

3012


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

4047


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1293


Write a program to model an exploding firecracker in the xy plane using a particle system

3866