Recursive algorithm
-------------------

``` {.java}
int foo (int n) {
  if (n <= 1) {
    return 0;
  } else {
    return 1 + foo(n-2);
  }
}
```

If `foo` is called with a positive *n*, what is returned?

a.  n
b.  0
c.  *n/2*
d.  2n
e.  `foo` will never finish, and thus will blow the call stack

Base case 1
-----------

``` {.java}
void clear(Stack<T> s) {
  if (!s.isEmpty()) {
    s.pop();
    clear(s);
  }
}
```

What is the base case of this recursive method?

a.  calling `clear()` makes the stack smaller
b.  a `StackUnderflowException` is thrown
c.  `s` has a finite number of elements
d.  *`s` is empty*

Base case 2
-----------

``` {.java}
int foo(int x) {
  if (x <= 1) {
    return 0;
  }
  else if (x % 2 == 1) {
    return x + foo(x + 1);
  }
  else { // x % 2 == 0
    return x + foo(x / 2)
  }
}
```

What is the base case of `foo`?

a.  `foo` won't terminate, since the three questions aren't satisfied
b.  *`x` is less than or equal to 1*
c.  `x` is even
d.  `x` is odd

Hanoi
-----

``` {.java}
public static void doTowers(int n, int startPeg, int auxPeg, int endPeg) {
  if (n > 0) {
    doTowers(n - 1, startPeg, endPeg, auxPeg);
    System.out.println("Move ring from " + startPeg + " to " + endPeg);
    doTowers(n - 1, auxPeg, startPeg, endPeg);
  }
}
```

How do we know that this algorithm makes progress toward the goal?

a.  we move at least one ring with each call
b.  the base case is `n > 0`
c.  *`n` decreases with each call*
d.  each call has a finite number of recursive calls (two, in this case)

Blob
----

```
X-X--XXX---X-XXXX--X--XXX--X--XXXXXX--X-------XXXX-------XX-X----------XX--------XXXXX------XX-XXXX----X---XX-
```

How many distinct blobs does the above image have?

a.  3
b.  *4*
c.  5
d.  6

Blob, answered
--------------

```
A-A--AAA---C-CCCC--D--AAA--A--CCCCCC--C-------AAAA-------CC-C----------AA--------CCCCC------AA-BBBB----C---CCC
```