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
Once multiple layers are selected which keyboard shortcut merges them
guajiro [1.7K]

Considering the computer system analysis, when the multiple layers are selected, the keyboard shortcut that merges them is "<u>Ctrl+E for (Windows) or Command+E for (Macbook)."</u>

<h3>What Keyboard Shortcut?</h3>

Keyboard Shortcut combines keyboard keys to ensure software programs perform specific functions.

Keyboard Shortcuts can be made by a Computer manufacturer as part of the standard functionality of the operating system or application program or made explicitly by the user in a scripting language.

Keyboard Shortcut is different in both Windows and Macbook Operating systems.

Hence, in this case, it is concluded the correct answer is "Ctrl+E for (Window) / Command+E for (Macbook)."

Learn more about Keyboard shortcuts here: brainly.com/question/14447287

4 0
2 years ago
If you omit the filename from a URL, the Apache web server displays a list of files and directories if the specified directory d
g100num [7]

Answer:

Default File

Explanation:

When a website is visited from a web browser without the explicit specification of the complete path of the file with the URL, the webserver will look for the file named index.html or index.php from the public_html files and render the contents of the file.

The name index. html or index.php is commonly used for the default page which is the page displayed to a visitor that does not specify a particular page for example (mysite/contact_us), so if the file path "contact_us" is omitted, the visitor will be taken to the "index" also known as the home page of "mysite".

6 0
3 years ago
What does it mean by null in programming?
Marysya12 [62]
In computer programming<span>, </span>null<span> is both a value and a pointer. </span>Null<span> is a built-in constant that has a value of zero. It is the same as the character \0 used to terminate strings in C. </span>Null<span> can also be the value of a pointer, which is the same as zero unless the CPU supports a special bit pattern for a </span>null<span> pointer.</span>
8 0
3 years ago
Suppose as a computer programmer, you have been assigned a task to develop a program to store the sorted data in ascending order
shepuryov [24]

Answer:

In case the data is arranged in the ascending order, you can always change the Binary search tree into a Height BST, and which is also known as the self-balancing BT. And through this, it's quite on hand to better the operations like searching on the new BST. And these SBBTs are quite commonly made use of for constructing as well as maintaining the ordered list. This is the case in the case of the priority queue, and this is what is required here.

Explanation:

Please check the answer.

3 0
4 years ago
A user reports that he cant browse to a specific website on the internet. From his computer, you find that a ping test to the We
ikadub [295]

Answer:

Incorrect DNS server address

Explanation:

7 0
2 years ago
Other questions:
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • What file formats can you safely use in a video presentation
    14·1 answer
  • A _____________ is a set of instructions used to perform calculations in a cell.
    14·1 answer
  • The component that allows you to make a paper-based copy of a body of text is the _____.
    12·1 answer
  • which of the following information technology career fields generally requires the lowest level of education for an entry level
    9·1 answer
  • What kind of user training should be conducted to deal with the issue of noise. How do you strike a balance between being overwh
    12·1 answer
  • To use an ArrayList in your program, you must import:1. the java.collections package2. the java.awt package3. Nothing; the class
    6·1 answer
  • These steps describe saving a newly created file.
    14·2 answers
  • A _______ is a host that runs software to provide information, such as web content, to other hosts.
    11·1 answer
  • LAB: Convert to binary - methods
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!