subject

The is a sum-the-data-in-the-tree question. It asks whether a method, sumAll() is a well-written recursive method. You will see three different versions of this question throughout the exam, but the opening assumptions, are identical for all such versions. The only difference between the various questions is the code that implements the method sumAll().

Assumptions:

The general tree in this problem is assumed to be physical, i. e., there is no lazy or soft deletion designed into this tree.

We are considering a recursive work-horse method to sum all the (assumed) integer data of the sub-tree.

The sub-tree is specified by the root pointer passed in. As usual, some client would pass a root to this method, then this recursive method would generate other (child or sibling) roots to pass to itself when recursing.

The members sib and firstChild have the same meanings as in our modules.

True of False:

The method, as defined below, is a good recursive method for summing the data of the sub-tree, based at the root node passed in.

To be true, it must satisfy all the following criteria. If it misses one, it is false:

It gives the right sum for the sub-tree, that is, it does not miss counting any data.

it does no unnecessary work, micro-management or superfluous testing.

It covers all situations (empty trees, NULL roots, handles all the children, etc.).

int TreeClass::sumAll(Node *root)

{

int sibSum, thisSum, childrenSum;

if (root == NULL)

return 0;

sibSum = sumAll(root->sib);

childrenSum = sumAll(root->firstChild);

thisSum = root->data;

return childrenSum + sibSum + thisSum;

}

HINT: There are three true-false questions that start out the same in this exam, but each has a different method definition. You may want to come back and review your answer to this question after seeing the other method definitions. Only one of the three is true,

and the other two are false.

True

False

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:30
What important technology has done the most to allow a businesses a chance to compete with larger international companies
Answers: 1
question
Computers and Technology, 23.06.2019 06:30
Martha is designing a single-player game. her manager suggests that she plan the design to incorporate future modifications. which principle of game design relates to planning for future modifications?
Answers: 1
question
Computers and Technology, 24.06.2019 02:30
Write the pseudo code for this problem based on what you learned from the video. the purpose is to design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. the conversion formula is as follows: miles = kilometers x 0.6214
Answers: 3
question
Computers and Technology, 24.06.2019 14:00
In simple terms, how would you define a protocol?
Answers: 2
You know the right answer?
The is a sum-the-data-in-the-tree question. It asks whether a method, sumAll() is a well-written rec...
Questions
question
Mathematics, 04.05.2021 16:30
question
Chemistry, 04.05.2021 16:30
question
Business, 04.05.2021 16:30
Questions on the website: 13722363