1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alekssandra [29.7K]
4 years ago
14

Recursively computing the sum of the first n positive odd integers, cont. About (a) Use induction to prove that your algorithm t

o compute the sum of the first n positive odd integers returns the correct value for every positive integer input.
Computers and Technology
1 answer:
julia-pushkina [17]4 years ago
6 0

The recursive function would work like this: the n-th odd number is 2n-1. With each iteration, we return the sum of 2n-1 and the sum of the first n-1 odd numbers. The break case is when we have the sum of the first odd number, which is 1, and we return 1.

int recursiveOddSum(int n) {

 if(2n-1==1) return 1;

 return (2n-1) + recursiveOddSum(n-1);

}

To prove the correctness of this algorithm by induction, we start from the base case as usual:

f(1)=1

by definition of the break case, and 1 is indeed the sum of the first odd number (it is a degenerate sum of only one term).

Now we can assume that f(n-1) returns indeed the sum of the first n-1 odd numbers, and we have to proof that f(n) returns the sum of the first n odd numbers. By the recursive logic, we have

f(n)=f(n-1)+2n-1

and by induction, f(n-1) is the sum of the first n-1 odd numbers, and 2n-1 is the n-th odd number. So, f(n) is the sum of the first n odd numbers, as required:

f(n)=\underbrace{\underbrace{f(n-1)}_{\text{sum of the first n-1 odds}}+\underbrace{2n-1}_{\text{n-th odd}}}_{\text{sum of the first n odds.}}

You might be interested in
Checking tire pressure should be performed:
vladimir2022 [97]

I would say the answer is D. Both A and C  because when it gets cold, the tires tend to become flat . You should also check once a month to make sure everything is fine especially after driving for a while!

8 0
3 years ago
Read 2 more answers
ITS A VOTE I NEED HELP
Mandarinka [93]

Answer: A block-level element is any element that starts a new line.

4 0
3 years ago
With a heat exchanger, the temperature of the process fluid can be measured with a temperature-
Ainat [17]
The answer is outlet cooling or process
6 0
3 years ago
Why it is so important for all application builders to always check data received from unknown sources, such as web applications
Aleks04 [339]
The already-long problem on hacking and other security-related cases necessitates for the application builders to check the data received from unknown sources. To further strengthen the security, even data received from known sources also need to be check as these may also contain harmful viruses creating critical problem to the application. 
6 0
3 years ago
What is the status of this account?
nydimaria [60]

Answer:

the answer is A my mom is a accountant and she pretty much told me everything she knows... lol

Explanation:

plz give brainliest and rating hope this helps^_^

5 0
3 years ago
Read 2 more answers
Other questions:
  • Casting is one of the oldest known manufacturing processes. <br> True or false
    6·2 answers
  • In controlling network traffic to minimize slow-downs, a technology called ________ is used to examine data files and sort low-p
    15·1 answer
  • Assume that input file references a Scanner object that was used to open a file. Which of the following while loops shows the co
    6·1 answer
  • What is 8 hours, 5 minutes, 22 seconds minus (-) 7 hours, 24 minutes, 37 seconds?
    6·1 answer
  • What should be done with statements or sections which are unclear?
    12·2 answers
  • In a ______topology, every device has exactly two neighbors for communication purposes. A failure in any cable or device can tak
    15·2 answers
  • What decides the amount of delay between shots on a digital camera?
    7·1 answer
  • TRUE OR FALSE: THE BUILDER'S CLUB IS A PAID SUBSCRIPTION.
    9·2 answers
  • How is the architecture converted into software code? Elaborate the steps its passes through with help of examples / Diagram.
    15·1 answer
  • Data frames can be subset by a chosen value using ==.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!