internal_nodes=TotalNodes(root) - No_of_leaf_nodes(root);

On Wed, May 9, 2012 at 1:19 PM, Amit Jain <[email protected]> wrote:

> Here is my version
>
> Algorithm count(x)
>
> 1: if (x==nil || (left[x]== nil and right[x]==nil))
> 2:      return 0
> 3: return count(left[x]) + count(right[x]) +1
>
> Time Complexity: O(n) where is n is total number of node in tree.
>
> Thanks
>
>
> On Wed, May 9, 2012 at 11:17 AM, Akshay Rastogi <[email protected]> wrote:
>
>> you are not checking whether the current node is an internal node or not
>> !!
>>
>> On Thu, May 3, 2012 at 12:47 AM, Rose <[email protected]> wrote:
>>
>>> Is this algorithm right or how shall I write it?
>>>
>>> *
>>> *
>>>
>>> *
>>> *
>>>
>>> *Construct an algorithm **Intern(**x**)**, which returns the number of
>>> internal nodes in the tree. *
>>>
>>> * *
>>>
>>> Algorithm Intern(x)
>>>
>>>
>>>
>>> 1: if (x = nil) then
>>>
>>> 2:      return 0
>>>
>>> 3: else
>>>
>>> 4:      return 1 + Intern(left[x]) + Intern(right[x])
>>>
>>> 5: end if
>>>
>>>
>>>
>>>  *a   -    **Give the time complexity/Running time of your solution in *
>>> *O**-notation. *
>>>
>>> --
>>> Med Venlig Hilsen/Kind regards
>>>
>>> Rose
>>>
>>>
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>
>>
>> --
>> AKSHAY RASTOGI
>> BE(Hons) CS
>> BITS PILANI , Pilani
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to