Read [Gray], Chapters 8 and 9. Consider the "Checkpoint" questions as part of your reading assignment: answer them but don't turn in your answers.You are encouraged to do all of these because many of the quiz and final exam questions will look surprisingly similar to them.
Use your CVS repository (or an SVN repository if you prefer) while working on this assignment.
Provide professionally crafted solutions to the following:
a(0, y) = y + 1 if y ≥ 0
a(x, 0) = a(x-1, 1) if x > 0
a(x, y) = a(x-1, a(x, y-1)) if x > 0, y > 0
(Throw an exception if x or y is null or less than zero —
you ought to know which one to throw.)
C(n, k) = 1, if k = 0 or k = n
= C(n-1, k-1) + C(n-1,k) if 0 < k < n
= undefined, otherwise
It can be shown that C can also be defined non-recursively:
C(n,k) = n! / (k!(n-k)!)
Give the
worst-case complexity of (a) the naïve recursive, (b) the
non-recursive algorithms for computing C(n, k).
public static void showStrings(char[] alphabet, int length) {
show("", alphabet, length);
}
For example, the call showStrings(new char[]{'a', 'b', 'c'}, 2) displays:
aa
ab
ac
ba
bb
bc
ca
cb
cc
Write the helper method show recursively. Since this method's
job is to print, you won't be writing a unit test for it. Later
in your career, you will see how to generalize this method so
it writes to a stream. Then a tester can pull from the stream
and perform tests. For now, just be happy inspecting the code
for correctness.Organize your work in your CVS (or SVN) repository with the following structure:
homework
cmsi281
src
main
docs
hw5.tex
<diagram source files>, if any
<images>, if any
java
edu
lmu
cs
math
StupidMathUtils.java
test
StringGenerator.java
test
java
edu
lmu
cs
math
StupidMathUtilsTest.java
Your LaTeX file will contain solutions to each problem, numbered, and in order. You may embed source code in the document, or give the answer as "See <filename>" and submit the sources for these answers at the end of the document. Generate a pdf from the LaTeX file and hand in a printed copy. Only turn in printed copies of your own files; do not waste trees by printing the sources for the code I gave you.
Notes