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]
3 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]3 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
Someone help me out eh?
Elodia [21]

Line 4

It should be font-size: 15px

Also there should be curly braces in line 5.

6 0
2 years ago
Read 2 more answers
Write Python code to save the data to a MongoDB collection:Import json module to parse JSON dataImport MongoClient from pymongo
Zigmanuir [339]

Answer:

Explanation:

The objective of this task is to compute a program that involves the usage of Python code to save the data to MongoDB and to query  the database.

Due to the error that occur which makes me to be unable to submit this answer, I've created a word document instead and the attached file can be found below.

Thanks!

Download docx
8 0
2 years ago
Write a little man program that accepts three values as input and produces the largest of the three as output.
ki77a [65]
Required: program to return the largest of three numbers.

pseudocode

input parameters, int A,B,C;
int T; // temporary storage
if (A>B) T=A;
else T=B;
if (T>C) print(T);
else print(C);


5 0
2 years ago
Identify 3 distractions for young drivers and explain how you plan to minimize these distractions.
Rom4ik [11]
1 distraction is phones , texting and driving . They could have a system in their car which activated by a voice assistant who could do it al for them
4 0
3 years ago
Consider the following code:
Deffense [45]

Answer:

The output of C is 102.

100 + 1 + 1 = 102

8 0
3 years ago
Other questions:
  • The CSS relative positioning property called ____ moves the element relative to its original position but preserves the space re
    9·1 answer
  • the control programs managing computer hardware and software use the ______ function to control and prioritize tasks performed b
    8·1 answer
  • List 5 anti-virus products currently in use
    15·1 answer
  • Which two encryption protocols might be used to provide secure transmissions for browser and web server communications?
    14·1 answer
  • Find the Nearest Repeated Entries in an Array People do not like reading text in which a word is used multiple times in a short
    15·1 answer
  • In working on the conceptual design of the new database, Ken determines that the "office" field in one of the tables must includ
    8·1 answer
  • Strengths and weaknesses about esport
    10·1 answer
  • Photo editing software, desktop publishing, email and word processing software is most likely to be used by:
    12·1 answer
  • Design a loop that asks the user to enter a number. The loop should iterate 10
    15·1 answer
  • HELP PLEASE
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!