Package algs11
Class MySecondHomework
java.lang.Object
algs11.MySecondHomework
This is a skeleton file for your homework. Edit the sections marked TODO. You
may add new functions. You may also edit the function "main" to test your
code.
You must not add static variables. You MAY add static functions, just not
static variables.
It is okay to add functions, such as
public static double sumHelper (double[] list, int i, double sumSoFar) {but it is NOT okay to add static variables, such as
public static int x;As for homework 1, you must not change the declaration of any method. You can edit the main function all you want. I will not run your main function when grading.

Constructor Summary

Method Summary
Modifier and TypeMethodDescriptionstatic void
draw
(double centerX, double centerY, double radius) PROBLEM 3: The following function draws mickey mouse, if you call it like this from main:static long
fibonacci
(int n) static void
A test program, using private helper functions.static void
static double
minValue
(double[] list) recursive versionstatic double
minValueI
(double[] list) iterative versionstatic void
reverse
(double[] a) static void
reverseI
(double[] a) PROBLEM 2: Do the same translation for this inplace reverse function You should write a helper method.static void
PROBLEM 5: The implementation of terribleFibonacci is TERRIBLE! Write a more efficient version of fibonacci.static void
PROBLEM 4: Run runTerribleLoop for one hour.static double
sum
(double[] a) static double
sumI
(double[] a) PROBLEM 1: Translate the following sum function from iterative to recursive.static long
terribleFibonacci
(int n)

Constructor Details

MySecondHomework
public MySecondHomework()


Method Details

minValueI
iterative version 
minValue
recursive version 
sumI
PROBLEM 1: Translate the following sum function from iterative to recursive. You should write a helper method. You may not use any "fields" to solve this problem (a field is a variable that is declared "outside" of the function declaration  either before or after). 
sum

reverseI
PROBLEM 2: Do the same translation for this inplace reverse function You should write a helper method. You may not use any "fields" to solve this problem (a field is a variable that is declared "outside" of the function declaration  either before or after). 
reverse

draw
PROBLEM 3: The following function draws mickey mouse, if you call it like this from main:draw (.5, .5, .25);
Change the code to draw mickey moose instead. Your solution should be recursive. Before picture: http://fpl.cs.depaul.edu/jriely/ds1/images/MickeyMouse.png After picture: http://fpl.cs.depaul.edu/jriely/ds1/images/MickeyMoose.png You may not use any "fields" to solve this problem (a field is a variable that is declared "outside" of the function declaration  either before or after). 
runTerribleLoop
PROBLEM 4: Run runTerribleLoop for one hour. You can stop the program using the red "stop" square in eclipse. Fill in the OUTPUT line below with the numbers you saw LAST  edit the line, replacing the two ... with what you saw: OUTPUT: terribleFibonacci(...)=... // TODO Comment: the code uses "long" variables, which are like "int", but bigger. It's because fibonacci numbers get really big really fast. 
terribleFibonacci

runFibonacciLoop
PROBLEM 5: The implementation of terribleFibonacci is TERRIBLE! Write a more efficient version of fibonacci. Do not change runFibonacciLoop or runFibonacciSomeValues. To make fibonacci run faster, you want it so that each call to fibonacci(n) computes the fibonacci numbers between 0 and n once, not over and over again. Comment: You will want to use a local variable of type "long" rather than type "int", for the reasons discussed above. Comment: At some point, your fibonacci numbers might become negative. This is normal and expected. http://en.wikipedia.org/wiki/Integer_overflow We discuss this at length in our systems classes. You may not use any "fields" to solve this problem (a field is a variable that is declared "outside" of the function declaration  either before or after). You may use a loop on this problem. You do not need to use recursion. 
fibonacci

main
A test program, using private helper functions. See below. To make typing tests a little easier, I've written a function to convert strings to arrays. See below. You can modify this  it is not graded. 
main1
