Need to fill out blanks or pages.
Since the chapter is more theoretical, the assignment is not as much about the code, but more about determining the theoretical program complexity (in Big-O notation), testing the boundaries of the code (e.g. large numbers, negative numbers, etc.) and handling difficult cases (with large runtime, memory/stack issues, etc). If you run into some of the issues, comment the line of code that causes the error (add a “//” at the beginning of it so I can see that you called it correctly), output “ERROR” in the runtime output table and explain your decision and why (the program should not run for a certain N values) in the Complexity document.
Hint: Did you watch my 2 videos for the chapter?
Hint: Pick an integral data type that can is large enough to hold your series value. int can only hold values up to 2147483647. If you need to hold values larger than that (without your program crashing), you need to pick a larger type – the type with maximum value of 9223372036854775807.
ASSIGNMENT 2A
Design a program/project/driver class (the program/project/driver class file should be called YourNameAssignment2A;
replace YourName with your actual name), that is going to show your understanding of program complexity on different
solutions to the same problem.
Part 1. Add to your YourNameAssignment2A driver class the following 3 methods (use the exact/precise names) to
compute Nth element of the following series (representing the sum of the squares of the first N positive integers):
1+22+32+…N2
Method Description
Method1 A recursive method with parameter N that used recursion to compute the Nth element in the series.
Method2 A brute method with parameter N that uses a loop to compute the Nth element in the series.
Method3 A mathematical method with parameter N that uses mathematic summation formula1 to compute the
Nth element in the series.
In your main method, call all the 3 methods Method1, Method2, and Method3 to determine which of the 3 methods is
faster by computing the run time 2 needed for the following 5 values for N : 100000 (a hundred thousand), 1000 (1
thousand), 10 (ten), -1000 (negative one thousand), and -1000000 (negative one hundred thousand) and output the
values or ERROR3 (if you run into a memory Overflow or Out of Memory issue even after using the largest integral type) in a table
format below (no lines needed) in which each cell has the run time for that method for that value for N.
N\Method Method1 Method2 Method3
100000
1000
10
-1000
-100000
Part 2. Compute the complexity of each of the 3 methods/algorithm using the Big O notation and add the calculations
for each of the 3 methods into a Microsoft Word document called YourNameAssignment2A-Complexity x (replace
YourName with your actual name). You should show the Big O notation calculation for the method complexity for each
one of the 3 methods. Which of the 3 methods is the best one? Add your answers to the document in the table bellow:
in column to the complexity of that method in Big-O notation and on the third column the Big O notation calculation for
the method complexity with explanations. For the Best Method, explain why the listed method is the best.
Method Complexity in Big O notation Calculation/Explanation
Method1
Method2
Method3
Best Method
Part 3: Create a document Create a Microsoft Word document called YourNameAssignment2A-Screeshots x (replace
YourName with your actual name) that contains screenshots of the complete JAVA source code in the IDE and the
complete program output. If the entire class JAVA source code or the output does not fit in one screenshot or the
screenshots cannot be easily read, create multiple screenshots and add them to the same document.
Submit YourNameAssignment2A.java JAVA source code file, YourNameAssignment2A-Complexity x complexity
analysis document, and YourName-Assignment2A-Screenshots Microsoft Word screenshots document on eCampus
under the Assignment2A. Do not archive the files (no ZIP, no RAR, etc) or submit other file formats. Review the files in
your eCampus submission confirmation window.
1 Look at this website to find the formula and, if interested, to see how it is computed https://brilliant.org/wiki/sum-of-n-n2-or-n3/
2 You can compute the run time using the System.nanoTime() method
3 Output “ERROR” if you run into a memory Overflow or Out of Memory issue even after using the largest integral type
https://brilliant.org/wiki/sum-of-n-n2-or-n3/
https://docs.oracle.com/javase/7/docs/api/java/lang/System.html#nanoTime()