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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:30, ansonhunter8891
What are listed in the vertical columns across the top of the event editor? a. file names b. conditions c. check marks d. action types
Answers: 1
image
Computers and Technology, 23.06.2019 11:30, talyku7131
Me dangers of social media and the internetexplain what each means: 1) social media and phones have become an addiction.2) outside people have access to you all the time.3) cyberstalking4) cyberbullying5) catphishing6) viruses7) identity theft8) credit card fraud9) hacking10) money schemes
Answers: 1
image
Computers and Technology, 23.06.2019 14:00, shawn423
How are stop motion special effects in animated films created
Answers: 1
image
Computers and Technology, 24.06.2019 10:00, wwwcarolynzouowficz
3. what do the terms multipotentialite, polymath, or scanner mean?
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 in other subjects: