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
Determining Correct Date Function What function text would you use to put today's date and time in a cell? 0 =TODAYO =NOWO O NOW
Murrr4er [49]

Current date formula:

=TODAY()

Current time formula:

=NOW()

As you can see, the =TODAY() formula only includes the day, month and year. The =NOW() function displays more information, showing the day, month, year, hour and minutes (using a 24-hour clock)

if useful mark as brainliest

3 0
3 years ago
What’s the answer for this
attashe74 [19]
I believe the answer is B<span />
3 0
3 years ago
Write a Console Java program to implement the following Sorting Program.
belka [17]

Answer:

Complete working code is available now.

Explanation:

Visit: gotit-pro.com/write-a-console-java-program-to-implement-following

Feel free to reach out to me for fastest, top-notch and impeccable homework help.

Thanks and Best Regards: Your Friendly Study Co-Pilot

6 0
2 years ago
Your essay is due tomorrow and you don't have time to write it. You decide to buy an essay online. You've paid for it, so it can
Reptile [31]

Answer:

FALSE

Explanation:

because even though you have paid for it , its still technically not writen by you . and would there for be seen as plagiarism......hope this helps

6 0
3 years ago
There are generally two ways of implementing dynamic programming solutions to problems, which have equal asymptotic time complex
san4es73 [151]

Answer:

1) Bottom-up

2) Top-down

Explanation:

In general dynamic programming is a divide and conquer strategy which can be implemented using bottom up approach or top down approach.

Bottom-up approach in dynamic programming will solve a relatively simple sub-problem first and then use the solution to build and arrive at solutions to a bigger sub-problem.

Top down approach is reversed to bottom-up approach and is also known as Memoization Method. Instead of solving a problem started from the base state sub-problem, the top down approach break a problem into a smaller problems from the top most destination state until it reaches the bottom most base state.

8 0
3 years ago
Other questions:
  • What do students buy when they pay tuition?
    6·2 answers
  • How is a cell named?
    9·1 answer
  • Which of the below statements describes the nature of HTML elements - check as many as apply
    6·1 answer
  • URGENT!
    15·1 answer
  • (Palindrome integer) Write the methods with the following headers // Return the reversal of an integer, i.e., reverse(456) retur
    9·1 answer
  • The syntax for accessing a class (struct) member using the operator -&gt; is ____.
    15·2 answers
  • What type of maintenance is required of a computer’s power supply to ensure that it remains in working order?
    15·2 answers
  • When Creating a FPS game what basic rules would you add?
    12·1 answer
  • WHICH PROGRAMMING LANGUAGES ARE THE BEST FOR PROGRAMMING?
    14·1 answer
  • In this lab, you complete a C++ program that uses an array to store data for the village of Marengo.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!