Purchase Solution

Binary Trees and Tree-Traversal

Not what you're looking for?

Ask Custom Question

Trace the following tree-traversal function, f(), and describe its action:

template <typename T>
int f(tnode<T> *t)
{ int n = 0, leftValue, rightValue;

if (t != NULL)
{
if (t ->left != NULL || t->right != NULL)
n++;
leftValue = f(t->left);
rightValue = f(t->right);
return n + leftValue + rightValue;
}
else
return 0;
}

Please provide a complete program if it makes sense.

Purchase this Solution

Solution Summary

This solution shows how to get a total nodes in a tree using tree-traversal algorithm.

Solution Preview

The function gets the total number of nodes with child or children in the tree, i.e., the number of non-leaf nodes.

Please see the attached files for the detail.

Trace the following tree-traversal function, f(), and describe its ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

C# variables and classes

This quiz contains questions about C# classes and variables.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Javscript Basics

Quiz on basics of javascript programming language.