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, 22.06.2019 12:30
What characteristic of long period comets suggest they come directly from the oort cloud?
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
The initial tableau of a linear programming problem is given. use the simplex method to solve it. x 1 x 2 x 3 s 1 s 2 z 1 2 4 1 0 0 8 3 4 1 0 1 0 10 minus3 minus12 1 0 0 1 0 the maximum is nothing when x 1equals nothing, x 2equals nothing, x 3equals nothing, s 1equals3, and s 2equals0. (be sure to simplify to lowest terms if necessary.)
Answers: 2
question
Computers and Technology, 24.06.2019 01:00
Mastercard managers are motivated to increase (1) the number of individuals who have and use a mastercard credit card, (2) the number of banks and other clents who issue mastercards to customers and/or employees, and (3) the number of locations that accept mastercard payments. discuss how mastercard could use its data warehouse to it expand each of these customer bases.
Answers: 3
question
Computers and Technology, 24.06.2019 17:00
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
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, 02.03.2021 20:00
question
Mathematics, 02.03.2021 20:00
question
Physics, 02.03.2021 20:00
question
Mathematics, 02.03.2021 20:00
Questions on the website: 13722366