internal_nodes=TotalNodes(root) - No_of_leaf_nodes(root);
On Wed, May 9, 2012 at 1:19 PM, Amit Jain 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
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 wrote:
> you are n
you are not checking whether the current node is an internal node or not !!
On Thu, May 3, 2012 at 12:47 AM, Rose 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.
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: en