For this task, save your work in hw1.pdf, SumEven.java The first n even numbers are 0,2,4,..., 2(n-1). This task involves computing the sum of the first n even numbers and understanding their performance implications. Subtask I We begin by writing a function public static long sumEven(int n) that computes the sum of the first n even numbers by looping over the even numbers in that range and adding them up. At the top of your function, answer the following question as a comment block: Approximately how many steps does this function need as a function of n? Subtask II Using the method discussed in Lecture 1, find a simple formula for the sum of the first n even numbers. Please show your work. Derive it directly without referencing other formulas. Subtask III If we are to use this formula instead of what we have in the sumEven function, how many steps would this implementation need when the input is n? Please answer this question in the PDF file.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
icon
Related questions
Question
For this task, save your work in hw1.pdf, SumEven.java
The first n even numbers are 0,2,4,..., 2(n-1). This task involves computing the sum of the first n
even numbers and understanding their performance implications.
Subtask I We begin by writing a function public static long sumEven(int n) that computes the sum
of the first n even numbers by looping over the even numbers in that range and adding them up.
At the top of your function, answer the following question as a comment block: Approximately
how many steps does this function need as a function of n?
Subtask II Using the method discussed in Lecture 1, find a simple formula for the sum of the first n even
numbers. Please show your work. Derive it directly without referencing other formulas.
Subtask III If we are to use this formula instead of what we have in the sumEven function, how many steps
would this implementation need when the input is n? Please answer this question in the PDF file.
Transcribed Image Text:For this task, save your work in hw1.pdf, SumEven.java The first n even numbers are 0,2,4,..., 2(n-1). This task involves computing the sum of the first n even numbers and understanding their performance implications. Subtask I We begin by writing a function public static long sumEven(int n) that computes the sum of the first n even numbers by looping over the even numbers in that range and adding them up. At the top of your function, answer the following question as a comment block: Approximately how many steps does this function need as a function of n? Subtask II Using the method discussed in Lecture 1, find a simple formula for the sum of the first n even numbers. Please show your work. Derive it directly without referencing other formulas. Subtask III If we are to use this formula instead of what we have in the sumEven function, how many steps would this implementation need when the input is n? Please answer this question in the PDF file.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr