just a thought ...

traverse the tree using whichever method you like. For each node you visit, check if it has any children. If not, count it as a leaf, because it is.

At the end of the algorithm, you will have the total number of children. This code works for any tree.

For example for a binary tree you can do in-order traversal using a recursive function

This is pseudocode adapted from a C/C++ version at http://datastructures.itgo.com/trees/traversal.htm

inorder(struct NODE curr)

{

if(curr->left != NULL)

inorder(curr->left);

if (both leaves are null)

count++;

if(curr->right != NULL)

inorder(curr->right);

}

You call this function by passing it root, i.e.

inorder(root);

Also have a global or some such variable called count. Initialize it to 0. It will be incremented by 1 for every leaf.

traverse the tree using whichever method you like. For each node you visit, check if it has any children. If not, count it as a leaf, because it is.

At the end of the algorithm, you will have the total number of children. This code works for any tree.

For example for a binary tree you can do in-order traversal using a recursive function

This is pseudocode adapted from a C/C++ version at http://datastructures.itgo

inorder(struct NODE curr)

{

if(curr->left != NULL)

inorder(curr->left);

if (both leaves are null)

count++;

if(curr->right != NULL)

inorder(curr->right);

}

You call this function by passing it root, i.e.

inorder(root);

Also have a global or some such variable called count. Initialize it to 0. It will be incremented by 1 for every leaf.