[algogeeks] Re: Height of a binary tree

2007-04-19 Thread BiGYaN
Yup dudes I agree it was a wrong program I have put the proper indentation without proper braces and that makes the code incorrect. The correct program would be : int getheight ( node *p ) { if ( p==NULL ) return 0; else { rh = getheight ( p->right );

[algogeeks] Re: Height of a binary tree

2007-04-18 Thread Arun
all the three statements following else shud be inside else block. On 4/18/07, pramod negi <[EMAIL PROTECTED]> wrote: > > I think this always return height 1. isn't it > > On 4/17/07, BiGYaN <[EMAIL PROTECTED]> wrote: > > > > > > We will be calling the function like : > > height = getheight(root);

[algogeeks] Re: Height of a binary tree

2007-04-18 Thread pramod negi
I think this always return height 1. isn't it On 4/17/07, BiGYaN <[EMAIL PROTECTED]> wrote: > > > We will be calling the function like : > height = getheight(root); > > and here's the function defination : > int getheight ( node *p ) > { >if ( p==NULL ) >return 0; >else >rh

[algogeeks] Re: Height of a binary tree

2007-04-17 Thread BiGYaN
We will be calling the function like : height = getheight(root); and here's the function defination : int getheight ( node *p ) { if ( p==NULL ) return 0; else rh = getheight ( p->right ); lh = getheight ( p->left ); return ( (lh>rh ? lh : rh)+1 ); } --~-

[algogeeks] Re: Height of a binary tree

2007-04-16 Thread Arun
getHt(node *n) > { > if (n) return ( max(getHt(n->left) + 1, getHt(n->right) +1); else return 0; } > > On 4/16/07, Virag Dhulia <[EMAIL PROTECTED]> wrote: > > > > HI Experts, > > > > I want to calculate the height of a binary tree recursively, any help > > will be appreciat

[algogeeks] Re: Height of a binary tree

2007-04-16 Thread Gautham Muthuravichandran
if u know the number of elements (n) height = ln n should do the trick On 4/17/07, Virag Dhulia <[EMAIL PROTECTED]> wrote: > > HI Experts, > > I want to calculate the height of a binary tree recursively, any help will > be appreciated > > -- > A man with dreams is never alone > > > --~--~---

[algogeeks] Re: Height of a binary tree

2007-04-16 Thread Arun
getHt(node *n) { if (n) } On 4/16/07, Virag Dhulia <[EMAIL PROTECTED]> wrote: > > HI Experts, > > I want to calculate the height of a binary tree recursively, any help will > be appreciated > > -- > A man with dreams is never alone > > > --~--~-~--~~~---~--~~ You