1 answer

ALGORITHM RecS(n) // Input: A nonnegative integer n ifn=0 return 0 else return RecS(n+ n n...

Question:

ALGORITHM RecS(n) // Input: A nonnegative integer n ifn=0 return 0 else return RecS(n+ n n n Determine what this algorithm computes. You must justify your answer. made by this algorithm and solve it. You must justify your answer. same thing using for/while loop(s) developed in (3). You must justify your answer. 1) 2) Set up the initial condition and recurrence relation for the number of multiplications 3) Write the pseudocode for the non-recursive version of this algorithm, i.e., compute the 4) Find the number of multiplications made by the non-recursive version of this algorithm

ALGORITHM RecS(n) // Input: A nonnegative integer n ifn=0 return 0 else return RecS(n+ n n n Determine what this algorithm computes. You must justify your answer. made by this algorithm and solve it. You must justify your answer. same thing using for/while loop(s) developed in (3). You must justify your answer. 1) 2) Set up the initial condition and recurrence relation for the number of multiplications 3) Write the pseudocode for the non-recursive version of this algorithm, i.e., compute the 4) Find the number of multiplications made by the non-recursive version of this algorithm

Answers

1) The algorithm computes sum of cubes of each number from 1 to n

So RecS(n) = 1^3 + 2^3 + ... + n^3

2)

RecS(n) = 0 => for n=0

RecS(n) = RecS(n-1) + n^3 => for n!= 0

In each iteration, there are 2 multiplications, hence, there will be completely 2n multiplications.

3)

result = 0;

for(int i=1; i<=n; i++) {

result = result + i*i*i;

}

4) The non recursive version, also makes 2 multiplications in each loop iterations, hence for n iterations, there will be 2n multiplications.

Thanks!

.

Similar Solved Questions

1 answer
At today’s spot exchange rates to one US dollar can be exchanged for 12 Mexican pesos...
At today’s spot exchange rates to one US dollar can be exchanged for 12 Mexican pesos or for 111.83 Japanese yen. Your pesos that you would like to exchange for yen. What is the cross rate between the yen and the pesos. That is how many Jan would you receive for every peso exchange?...
1 answer
Details The physician has just diagnosed your best friend with Hashimoto's disease. Using only credible, trustworthy...
Details The physician has just diagnosed your best friend with Hashimoto's disease. Using only credible, trustworthy websites, find out: The signs and symptoms of Hashimoto's disease The recommended treatment or treatments for Hashimoto's disease Share these details, in your own words....
1 answer
What is the distance between # (-6, -6) # and # (5,2) #?
What is the distance between # (-6, -6) # and # (5,2) #?...
1 answer
A graduate has just taken out an amortized car loan of $30,000 today. The loan has...
A graduate has just taken out an amortized car loan of $30,000 today. The loan has a 3.00% APR with monthly compounding. The term of the loan is 7 years. The graduate would like to pay off the loan early and plans on paying the remaining balance after the 3rd year of payments. What will be the loan ...
1 answer
(Note: select all correct answers) The optimal risky portfolio can be identified by finding the minimum...
(Note: select all correct answers) The optimal risky portfolio can be identified by finding the minimum variance point on the efficient frontier the maximum return point on the efficient frontier the tangency point of the capital market line and the efficient frontier the line with the steepest slop...
1 answer
Calculate the internal normal force, internal shear force, and internal bending moment at a location 0.75m...
Calculate the internal normal force, internal shear force, and internal bending moment at a location 0.75m to the right of the fixed support A. 2. (20 points) Calculate the internal normal force, internal shear force, and internal bending moment at a location 0.75m to the right of the fixed supp...
1 answer
The myeloperoxidase stain will be strongly positive in: Acute promyelocytic leukemia has a high incidence of...
The myeloperoxidase stain will be strongly positive in: Acute promyelocytic leukemia has a high incidence of which of the following cytogenetic abnormalities? Select one: O a.t(8,21) (q22;q22) obt(9:11) (p22;923) O c. t(15;17) (722;q12) d. inv(16) (p13922)...
1 answer
Problem 1: (10 points) An integrated circuit is available to serve as a feedback s output voltage of a power supply. The Bode diagram of the required loop transfer function Ge Go)G(jw) is shown b...
Problem 1: (10 points) An integrated circuit is available to serve as a feedback s output voltage of a power supply. The Bode diagram of the required loop transfer function Ge Go)G(jw) is shown below. Estimate the gain and phase margins of the regulator (yes you need to extrapolate). system to regul...
1 answer
Explain the difference between the terms factors and treatments. Give an example.
Explain the difference between the terms factors and treatments. Give an example....
1 answer
What is the equation of the line normal to # f(x)=sec4x-cot2x# at # x=pi/3#?
What is the equation of the line normal to # f(x)=sec4x-cot2x# at # x=pi/3#?...
1 answer
Name three federal or state health care laws that have had a meaningful impact on at...
name three federal or state health care laws that have had a meaningful impact on at least one population or segment of the health care industry...
1 answer
How do you solve #-\frac{4}{7}v=-8\frac{2}{3}#?
How do you solve #-\frac{4}{7}v=-8\frac{2}{3}#?...
1 answer
The Alves Company retails two products: a standard and a deluxe version of a luggage carrier....
The Alves Company retails two products: a standard and a deluxe version of a luggage carrier. The budgeted income statement for next period is as follows: (Click the icon to view the budgeted income statement) Read the requirements. Requirement 1. Compute the breakeven point in units, assuming that ...
1 answer
Phlebotomy 130 Unit in Blood Collection Procedures MATCHING Use choices only once unless otherwise indicated. MATCHING...
phlebotomy 130 Unit in Blood Collection Procedures MATCHING Use choices only once unless otherwise indicated. MATCHING 7-1: KEY TERMS AND DESCRIPTIONS Match each key term with the best description. Key Terms ACD Additive Anticoagulants Antiglycolytic agent Antiseptics Bevel Biocide Blood c...
1 answer
Fill up empty boxes with the correct chemical structures Fill up the empty boxes with the...
Fill up empty boxes with the correct chemical structures Fill up the empty boxes with the correct chemical structures. ??...
1 answer
Use the molecular orbital scheme to explain cobaltocene
use the molecular orbital scheme to explain cobaltocene...