Saturday, April 13, 2013

Teaching AP Computer Science: Continuing Chapter 18, Recursion!



Teaching AP Computer Science: Continuing Chapter 18, Recursion! 

This week we started Recursion. We are overriding the Math class by writing our own Math.java static class! We started by overloading the pow() method:

public static int pow(int base, int exp),
public static int pow(double base, int exp),
public static int pow(double base, double exp).

That way we can test each method separately. We want to compare interation to recursion to the standard Math.pow() method. So, the first pow() uses a product for loop. The second pow() uses recursion based on the fact that base^exp=base*base^(exp-1). The last pow() method with use log() and exp(). My students will be in for a rude awakening when they try to use Math.log() and Math.exp() from the standard java.lang.Math class....

Then we added:
public static int fact(int n)
public static int fib(int n)
public static int pascal(int n, int r)

We have a Take Home due this Monday on recursive methods. We will follow recursion with GridWorld Part IV and AP Review! BTW, Chapter 19 on Searching and Sorting Algorithms will be sent home as a reading assignment. Searching and Sorting isn't a big topic on the AP Computer Science exam anymore and we need time for AP Review.

Here's our ScreenCasts and Code for this last week:

 





myPasteBin code for APCS2012
myProgramr code for APCS2012

Well, that's all folks!
Teaching with Technology, 

No comments:

Post a Comment