Write a function to find the depth of a binary tree.
Answer Posted / sanjeev sindhu
int depth(treenode *p)
{
if(p==NULL)return -1 ;
if(p->left){h1=depth(p->left);}
if(p=>right){h2=depth(p->right);}
return(max(h1,h2)+1);
}
Check the boundary condition for p =NULL means no tree exists.
so depth should be -1 if only root node is there then depth
of the tree is 0.
Is This Answer Correct ? | 13 Yes | 14 No |
Post New Answer View All Answers
could you please send the program code for multiplying sparse matrix in c????
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
why nlogn is the lower limit of any sort algorithm?
#include
How to palindrom string in c language?
how to test pierrot divisor
Write a routine to implement the polymarker function
Design an implement of the inputs functions for event mode
Hi, i have a project that the teacher want a pyramid of numbers in C# or java...when we click a button...the pyramid should be generated in a listbox/or JtextArea...and the pyramid should have the folowing form: 1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210 Plz help with codes...didn't find anything on the net.
Sir... please give some important coding questions asked by product companies..
how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns
Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange
Cluster head selection in Wireless Sensor Network using C programming language.
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
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??