Q1: 20 points Q2: 55 points Q3: 35 points Total: 110 points
For example, A(0) = 0, A(1) = -1, A(2) = -1 + 3 = 2, and A(3) = -1 + 3 - 5 = -3. (Note that (-1)i is 1 if i is even and -1 if i is odd.)
Find a closed-form formula for A(n) (a simple expression with no summation) and prove it correct for all n by induction. (It is possible to do this either by ordinary or by odd-even induction.)
You may choose to prove ∀n:P(n) ∧ Q(n) by ordinary induction, to prove ∀n:P(n) and ∀n:Q(n) separately by odd-even induction, or to prove both by strong induction.
If w is a string of letters, we define the score of w by two rules:
Here are your questions:
scoreOf
that
takes a string w and returns the score of w. You may assume that a method
lab
has already been defined as above. Do not worry about error
handling, such as for invalid characters in w.
Last modified 3 April 2006